When a method is declared as virtual
in a class, its overrides in derived classes are automatically considered virtual
as well, and the C++ language ma
As a related note, in C++0x you have the option of enforcing being explicit with your overrides via the new attribute syntax.
struct Base {
virtual void Virtual();
void NonVirtual();
};
struct Derived [[base_check]] : Base {
//void Virtual(); //Error; didn't specify that you were overriding
void Virtual [[override]](); //Not an error
//void NonVirtual [[override]](); //Error; not virtual in Base
//virtual void SomeRandomFunction [[override]](); //Error, doesn't exist in Base
};
You can also specify when you intend to hide a member via the [[hiding]]
attribute. It makes your code somewhat more verbose, but it can catch a lot of annoying bugs at compile time, like if you did void Vritual()
instead of void Virtual()
and ended up introducing a whole new function when you meant to override an existing one.