A
Asif Zaidi
Hi:
I have the 2 classes below. I am trying to cast them such that output
should be different. But I am getting to be the same all the time.
Suggestions only plz. Thanks
class Base { public: virtual void foo() {} };
class Derived : public Base { public: virtual void foo() { cout << "
in derived" << endl; } };
int main()
{
Derived dobj;
Base *b = &dobj;
cout << dynamic_cast<Derived*>(b) << endl;
cout << reinterpret_cast<Derived*>(b) << endl;
}
I have the 2 classes below. I am trying to cast them such that output
should be different. But I am getting to be the same all the time.
Suggestions only plz. Thanks
class Base { public: virtual void foo() {} };
class Derived : public Base { public: virtual void foo() { cout << "
in derived" << endl; } };
int main()
{
Derived dobj;
Base *b = &dobj;
cout << dynamic_cast<Derived*>(b) << endl;
cout << reinterpret_cast<Derived*>(b) << endl;
}