Explicit override syntax
In standard C++, derived classes override base class functions specified as virtual. Base classes must explicitly define a function as virtual in order for it to be so. However, derived classes are not required to use the keyword virtual for their overriding. Additionally, it is possible to misspell a function name, or use the wrong parameter list, which results not in overriding, but in the creation of a new function or overload by accident. Lastly, it is possible to introduce a new virtual function in a derived class, but the author of the base class introduces a new virtual function with the same name and signature in the base class at a later time, causing unusual behavior.
C++0x fixes all of these problems. The derived class can be marked with the keyword explicit, which forces the derived class to be more specific about its intensions with regard to virtual functions:
Code:
class BaseClass
{
virtual void Func1();
virtual void Func2(int);
};
class DerivedClass explicit : public BaseClass
{
virtual void Func1(); //Overrides BaseClass::Func1
void Func2(int); //Illegal. Must use keyword ''virtual'' for overrides
new virtual void Func3(int); //Introduces a new virtual function.
virtual void Func4(float); //Illegal. Must use keyword ''new'' for new virtuals
virtual int Func2(int); //Illegal. Signature does not match BaseClass::Func2;
};