#include using namespace std; class Base { public: Base ( void ); virtual ~Base ( void ); virtual int g ( int a = 0 ); }; Base::Base ( void ) { } Base::~Base ( void ) { } int Base::g ( int a ) { return ( a + 1 ); } class Derived : public Base { public: Derived ( void ); virtual ~Derived ( void ); virtual int g ( int a = 0 ); //遵循1 }; Derived::Derived ( void ) { } Derived::~Derived ( void ) { } int Derived::g ( int a ) { return ( a + 2 ); } int main ( void ) { int i, j; Derived d; Base &b = d; i = b.g ( ); j = d.g ( ); return ( 0 ); }