How can I protect from accidental definition of non-inherited method where inherited definition is intended. I am told there is trick to express it, but nobody can recall it
For this exact purpose C++0x introduces the override member function decorator, as is already implemented in VC++ 2005 and later: http://msdn.microsoft.com/en-us/library/41w3sh1c.aspx
Alternatively, VC++ permits the following (presumably compiler-specific):
#include
class Base {
public:
virtual void VeryLongFunctionName(int VeryLongArgumentList) = 0;
};
class C : public Base {
public:
void Base::VeryLongFunctionName(int VeryLongArgumentList) {
std::cout << "C::\n";
}
};
class D : public C {
public:
void Base::VeryLongFunctionNane(int VeryLongArgumentList) {
// ^^^^^^ now causes a compilation error
std::cout << "D::\n";
}
};