I use a class A from a library and want to add some functionality to it via an own class B. The user of class B should derive from it as if he would derive from class A.
class A {
public:
virtual void func1()=0;
virtual void func2()=0;
...
}
class B: public A {
public:
virtual void func1() {...}
}
So if someone creates a class C deriving from B, he should have to implement func2:
class C: public B {
public:
virtual void func2() {...}
}
It is very important for my application, that class C doesn't overwrite func1, eliminating B::func1().
Is there a way to forbid overwriting this virtual function for all child classes of B? If not in plain C++, is there something in boost MPL that throws a compiler error, when this function is overwritten?
A
should overridefunc2
and if not, why is it virtual? – Faricanew C
'ing a new ponter the compiler would try to set it to function in the most-derived class. Stopping in the middle of the derive-chain would break the intent of virtual functions. – SpoilerB::func1
is not overridden? – Rheumfinal
keyword in 4.7. – Vinnievinnitsa