There are good reasons for creating a base class interface with all virtual functions, both private and protected (see this ). But how can we prevent derived classes (which may be in the hands of external clients) from creating a private virtual function as public? In "Practically Yours" the authors talk about this problem, but the solution is not discussed.
Change . From your answers and, as I thought before, it seems that this is impossible to prevent. But since it is easy to make a mistake in this situation (the client necessarily touches on a protected virtual function), it would be reasonable that the compiler warned about this use. I tried to check it with g ++. First, I wrote:
class A {
protected:
virtual void none() { return; }
};
class B: public A {
public:
void none() { return; }
};
g++ -c -Wall -pedantic file.cppcompiled without errors. Adding -Weffc++gave a warning: warning: ‘class A’ has virtual functions and accessible non-virtual destructorthat makes sense. After adding a virtual destructor, there is no warning. Thus, there are no warnings regarding this simple case.
source
share