View Single Post
  #1 (permalink)  
Old November 5th, 2004, 07:23 AM
rstaveley rstaveley is offline
Registered User
 
Join Date: Nov 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Visual C++ .NET: A primer for C++ developers error

On page 51, when discussing abstract classes, it says that writing default implementations for all methods in abstract classes is not possible using C++'s pure virtual syntax.

That's not true.

Try the following C++:

--------8<--------
#include <iostream>

struct base {
    virtual void f() = 0;
};

void base::f()
{
    std::cout << "base::f() called\n";
}

struct derived : public base {
    void f();
};

void derived::f()
{
    std::cout << "derived::f() called\n";
    base::f();
}

int main()
{
    derived d;
    d.f();
}
--------8<--------

You can define default implementations for PVFs.