In C++11 we have override specifier that allows to validate in compile time that virtual function actually overrides behavior of interface in the base class.
Is there anyway to get the same behavior in C++03?
In C++11 we have override specifier that allows to validate in compile time that virtual function actually overrides behavior of interface in the base class.
Is there anyway to get the same behavior in C++03?
To check if a function foo exists in a base class Foo say, write
sizeof(&Foo::foo);
in the child class version of foo. The idea is that compilation will fail if the base class Foo::foo is not present, and has a benign effect if it is.
Of course, this has drawbacks - you can't descriminate by overloads for example. Also, static functions and member variables with a similar name will also match.