class A { public: virtual void test() const = 0; }; void A::test() const { cout << "default" << endl; } class B :public A { }; int main() { B* b; b->test(); }
令人意外的是,我们可以为pure virtual提供定义。
class A { public: virtual void test() { cout << "default" << endl; } }; class B :public A { public: }; int main() { B* b = new B; b->test(); }