Adding New Methods to Already-Declared Classes?

Hi,

I would like to know if there is a way to extend the functionality of already-declared classes by adding methods outside of the class declaration?

For example, let's say I wanted to add a new method to std::string that automatically converted the contents to an int. Is there any way to do this without modifying <string> and without creating a derived class? Of course, I know there are other ways to perform such conversions without modifying the class, I'm just asking this as an example.

So, for instance, if I have
1
2
3
4
struct Foo{
	int size();
	int length();
};


And I would like to add a new method, int Bar() to Foo outside of the Foo declaration, is this in any way possible (without using a derived class)?

Thanks!
No, your only option is derivation.
Everybody loves a happy ending. Well, thanks anyway.
Topic archived. No new replies allowed.