Is there a way to add new methods to a class, without modifying original class definition (i.e. compiled .lib containing class and corresponding .h file) like C#\'s class ex
There is one way in which it can be done. And that's by relaxing your requirements a bit. In C++, people often say that the interface of a class consists not just of its member functions, but of all functions that work on the class.
That is, non-member functions which can be given the class as a parameter should be considered part of its interface.
For example, std::find()
or std::sort()
are part of the interface of std::vector
, even though they aren't members of the class.
And if you accept this definition, then you can always extend a class simply by adding nonmember functions.