Antoninus said:
class B : public A [snip]
A newA = mystack.top( );
B b = (B) newA; //doesnt work here
how could I do downcast???
Since B is derived from A, in general it doesn't make sense to cast from
A to B.
If you happen to know that the object you've popped is actually a B,
then you can convert (a pointer to the object) with dynamic_cast. (If
the cast isn't valid, then dynamic_cast will return NULL.)
Both off topic and plain wrong.
Whether it's off topic is a matter of opinion.
If it's wrong, why not point out the error instead of hurling mud?
I freely admit that I'm not a C++ expert, but I know enough to get by,
and given that the people here who *are* C++ experts will refuse to help
because they'd rather play topicality games, I'll give it my best shot.
I think the following is true:
1) What I've said above is correct (assuming A is polymorphic)
2) Using a dynamic_cast instead of a static_cast is safer in the
situation above, where error-checking that what comes off mystack really
is of type B could be valuable.