Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Huh. Does that mean I can write

    class A {
    public:
    virtual void foo() = 0;
    };
    void A::foo() {}
    class B: public class A {};
    B b;
    b.foo();
and that will work?


No, it will complain that A::foo is pure virtual, and that B must implement `foo`. However, if you define in B the method `void foo() { A::foo(); }`, it will work. In destructors this happens implicitly.

There was an old Herb Sutter GotW about this: http://www.gotw.ca/gotw/031.htm




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: