In Visual C ++, you can use the override extension. Like this:
virtual void func() override { std::cout << "DERIVED" << std::endl; }
This will give an error if the function does not actually override the base class method. I use this for ALL virtual functions. I usually define a macro as follows:
#ifdef _MSC_VER #define OVERRIDE override #else #define OVERRIDE #endif
Therefore, I can use it as follows:
virtual void func() override { std::cout << "DERIVED" << std::endl; }
I was looking for something similar in g ++, but could not find a similar concept.
The only thing I don't like about Visual C ++ is that you cannot force the compiler (or at least warn) the compiler to execute all overridden functions.
Aaron
source share