Suppose
what is the difference between:Code:class Derived: public Base{ ... };
ANDCode:Derived * d = new Derived; Base* b = static_cast<Base*>(d);
Code:Derived d ; Base b = static_cast<Base>(d);
Suppose
what is the difference between:Code:class Derived: public Base{ ... };
ANDCode:Derived * d = new Derived; Base* b = static_cast<Base*>(d);
Code:Derived d ; Base b = static_cast<Base>(d);
Last edited by meili100; 06-07-2007 at 12:07 PM.
Polymorphic relationships don't hold for actual objects.
That is:
A Derived* is a Base*
A Derived& is a Base&
But a Derived is NOT a Base. Such a conversion results in slicing, and you lose pieces of your objects.
There is no greater sign that a computing technology is worthless than the association of the word "solution" with it.
The second one makes a copy of the object and casts it (which is where the slicing happens). The first one makes a copy of the pointer and casts it, so the object is still there.