On Jan 17, 4:35 pm, "Paul"<pchrist<nospam>o...@yahoo.co.uk> wrote:
I think its a handy feature for supplying some default functionality.
But, as far as I can tell, the only benefit over a protected non-
virtual is that you use the same name when calling, so you can write:
class Base
{
public: virtual void f() = 0;
};
void Base::f()
{
//whatever
}
class Derived : public Base
{
public: virtual void f() {
Base::f();
// Derived-specific stuff goes here.
}
}
/// Alternatively, without this language feature
class Base
{
protected: void f_helper() {
//whatever
}
public: virtual void f() = 0;
};
class Derived : public Base
{
public: virtual void f() {
f_helper();
// Derived-specific stuff goes here.
}
}
Is it handy? Well arguably, yes, but its not *very* handy, especially
as I can define f_helper() inline, but can't do so for Base::f().
header file and use the inline keyword.