
February 1st, 2003, 01:48 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
Why not add a class type in the base class (parent), so that when popping it, you can assign it to a variable of the base class. Then determine the class type and cast it accordingly. Of course, if you already have RTTI information in your base class, there's no need to put a class type.
Code:
Stack s;
Child1 c1;
Child2 c2;
Parent p;
s.push(c1);//thats OK
s.push(c2);//thats OK
p = s.pop();
if (p.type == "c1")
c1 = dynamic_cast <Child1> p;
else if (p.type == "c2")
c2 = dynamic_cast <Child2> p;
Hope this helps!
Last edited by Scorpions4ever : February 2nd, 2003 at 12:43 AM.
|