Re: Private implementation of public pure virtual
Alf P. Steinbach wrote:
It concerns the very same issue. Access specifiers and virtuality (the
ability to override) are orthogonal features: one does not affect the
other, at the technical level. The issue is then how these features can
or should be meaningfully mixed at the design level.
and also IMHO that faq is quite misleading.
Could you please elaborate on that, so that the FAQ could be improved?
Actually while I agree that it is better to have the virtual methods
protected rather than public it is not for the reason stated in the
FAQ.
The reason it is better for them to be protected is so that a derived
class can invoke as part of its implementation of the function the
method in its super class.
Thus:
class A
{
public:
virtual ~A();
void f() { do_f(); }
protected:
virtual void do_f() = 0;
};
class B : public A
{
protected:
virtual void do_f() { // implementation }
};
class C : public B
{
protected:
virtual void do_f()
{
// do some stuff
B::do_f();
// do some more stuff
}
};
Of course you can change the access specifiers only for those specific
classes that may have another one derive from them and call the base
class behaviour but that means prior knowledge of what may derive from
your class.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]