c++ - Is there another way to call Base method from derived which is virtual -
i wondering if there way call virtual base method derived instead of:
void y() //is virtual in base { base::y(); }
if duplicate, i'm sorry.
regardless of why want this, can achieve same thing using alternate syntax. add resolution syntax dereferencing of variable (the same can achieved non-pointers dereferenced .
operator)
#include <iostream> using namespace std; class { public: virtual void x( ) { cout << "a::x()\n"; } virtual void y( ) { cout << "a::y()\n"; } }; class b : public { public: virtual void x( ) { cout << "b::x()\n"; } virtual void y( ) { cout << "b::y()\n"; } }; void main( ) { b* xb = new b( ); a* xa = xb; xb->x( ); xb->y( ); xa->x( ); xa->y( ); xb->a::x( ); xb->a::y( ); system( "pause" ); }
Comments
Post a Comment