Call base virtual function explicitly : base class « Class « C++ Tutorial






#include <iostream>

using namespace std;

class Base {
public:
   virtual void foo( ) {cout << "Base::foo( )" << endl;}
};

class Derived : public Base {
public:
   virtual void foo( ) {cout << "Derived::foo( )" << endl;}
};

int main( ) {
   Derived* p = new Derived( );

   p->foo( );       // Calls the derived version
   p->Base::foo( ); // Calls the base version
}
Derived::foo( )
Base::foo( )








9.17.base class
9.17.1.Add a constructor to Base class
9.17.2.Add a overloaded constructor to base class
9.17.3.Call base's default constructor automatically
9.17.4.Call base virtual function explicitly
9.17.5.Virtual base classes
9.17.6.Pass parameter to two base classes