C++: call pure virtual function from member function of same class
问题 Consider the following 2 programs. #include <iostream> using std::cout; class Base { public: virtual void f()=0; void g() { f(); } virtual ~Base() { } }; class Derived : public Base { public: void f() { cout<<"Derived::f() is called\n"; } ~Derived() {} }; class Derived1 : public Base { public: void f() { cout<<"Derived1::f() is called\n"; } ~Derived1() { } }; int main() { Derived1 d; Base& b=d; b.g(); b.f(); } Compiles & runs fine and gives expected outcome.. #include <iostream> using std: