Ah, yes..so that was what that bloody error was.
*Penny in the air*
Let me try to explain it IMOW...
Because a Square IS A Shape..I can store the bloody square in the Shape object. What happens is the base constructor is first called (If I remember correctly, it said so in the Deitel book). It copies the data members and member functions into the Shape object...but instead of calling the Square constructor it doesn't like tabstop said...so the only thing left in Shape a is a Shape object...the compiler implicitly does it.
But when I try to do the reverse, a Shape IS NOT A Square..and its base constructor is not a Square (although if I am really evil I could lie to the compiler)..but if I really wanted to do it I must explicitly provide a copy constructor in the Square class and that should solve the problem.
*Did the penny drop?*
What is Rtti? Run time type...?The polymorphism only works so long as you are dealing with method calls through a pointer, or doing rtti queries with the pointer
In this case the type being Shape, not Square...but if it the function was virtual..it'd be Square? Ha ha *rolls eyes*but once you dereference to get the actual object then it will be of the type that the pointer says it is.
Is it impossible to downcast in C++?
I tried this without assigning it
((Square)a).draw() ;
I would have thought that was possible..I must be doing something wrong, I am sure my lecturer did something like this before.
EDIT:
Oh yeah, it works like this
Code:(dynamic_cast<Square*>(b))->draw(); //or ((Square*)b)->draw() ;