A
Abhijit Deshpande
Is there any elegant way to acheive following:
class Base {
public:
Base() {}
virtual ~Base() {}
virtual void Method() { cout << "Base::Method called"; return;
}
};
class Derived : public Base {
public:
Derived() {}
~Derived()
void Method() { cout << "Derived::Method called"; return; }
};
int main() {
Derived deriveObj;
Base * basePtr = 0;
basePtr = <some kind of cast????> &deriveObj;
basePtr->Method();
}
In the above code, the call "basePtr->Method" should print
"Base::Method called" and not "Derived::Method called".
Is there any way to assign address of "deriveObj" to "basePtr" so that
the virtual mechanism is bypassed and call to member function "Method"
actually calls the member function from the "class Base" and not from
"class Derived".
Thanks in advance,
Regards,
Abhijit.
class Base {
public:
Base() {}
virtual ~Base() {}
virtual void Method() { cout << "Base::Method called"; return;
}
};
class Derived : public Base {
public:
Derived() {}
~Derived()
void Method() { cout << "Derived::Method called"; return; }
};
int main() {
Derived deriveObj;
Base * basePtr = 0;
basePtr = <some kind of cast????> &deriveObj;
basePtr->Method();
}
In the above code, the call "basePtr->Method" should print
"Base::Method called" and not "Derived::Method called".
Is there any way to assign address of "deriveObj" to "basePtr" so that
the virtual mechanism is bypassed and call to member function "Method"
actually calls the member function from the "class Base" and not from
"class Derived".
Thanks in advance,
Regards,
Abhijit.