Maybe a silly question.
Suppose I have the following:
class A{
int x;
int y;
virtual int get_thing(){return x;}
};
class B : public A {
int get_think(){return y;}
};
In the example above, B::get_thing returns x because the overriding code has a typo.
How can I ensure, at compile time that the get_thing function has been overridden in class B so that it returns y?
Assuming
A::get_thingis virtual, and assumingclass Bis derived fromclass A, and you have C++11 support, you can use theoverridespecial identifier:This would produce a compiler error. Note that this is based on the signature of the method, i.e. its name, cv qualifiers, and types of the parameters. The return type or the body of the function do not come into it.