// ---------------------------------------------------------------------- // // virtovrd.cc - Can we override virtual functions in a derived class? // // History: // 28-Aug-2000 WEB Initial draft // 18-Jan-2001 WEB Remove unused function argument's name // 29-Jan-2001 WEB Remove pointers' const qualification to avoid // tickling DEFECT_NO_DELETE_CONST // 25-Apr-2001 WEB s//"ISOcxx\/ISOcxxSyntax.hh"/ // // ---------------------------------------------------------------------- #include "ISOcxx/ISOcxxSyntax.hh" class B { public: B() { ; } virtual int f( int ) const { return 1; } virtual int f( double ) const { return 2; } }; // B class D : public B { public: D() { ; } #ifndef DEFECT_NO_VIRTUAL_OVERRIDE using B::f; #else // defective virtual int f( double ) const { return 2; } #endif virtual int f( int ) const { return 3; } }; // D int main() { int result = 0; { B * bp = new B; if ( 1 != bp->f(0) ) result += 1; // B::f(int) if ( 2 != bp->f(0.0) ) result += 2; // B::f(double) delete bp; } { D * dp = new D; if ( 3 != dp->f(0) ) result += 4; // D::f(int) if ( 2 != dp->f(0.0) ) result += 8; // D::f(double) delete dp; } { B * bp = new D; if ( 3 != bp->f(0) ) result += 16; // D::f(int) if ( 2 != bp->f(0.0) ) result += 32; // B::f(double) delete bp; } return result; } // main()