Every object in .NET inherits (directly or indirectly) from the common root base \"Object\". Is there such a common object root in C++? How do I pass any object to
Template functions are present and avoid the need for such root parent of all classes.
template <class T>
void DoSomeStuff(T const &t) {
// Do the stuff with t...
t.callTheFunction();
}
If all your objects have a member function callTheFunction(), then you got the exactly same behavior than having a root base class, with the same requirement (all your classes have a function with that name).
In addition, you got the additional benefit of being able to specialize the template function DoSomeStuff()
for some classes that are not yours, and could not inherit your virtual member function.