C++ examples for Class:Virtual Function
Calling a Superclass Virtual Function
#include <iostream> using namespace std; class Base {/*from w ww. j av a 2s .co m*/ 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 }