class object {
public:
virtual ~object() = 0;
};
inline object::~object() {}
class stack {
struct Link {
object *data;
Link *next;
Link(object* o, Link* n): data(o), next(n) {}
} *top;
public:
stack(): top(0) {}
~stack() {
while(top)
delete pop();
}
void push(object* o) {
top = new Link(o, top);
}
object *pop() {
if (top == 0) return 0;
object *tmp = top->data;
Link *l = top;
top = top->next;
delete l;
return tmp;
}
};
i think the bold code does :
create a pointer to class object and share with object data same adress in memory.
create a pointer to class link share with object top the same adress in memory.
assing to object top the adress memory of object next .
detele pointer l
return tmp wich is pointing to same class object?
what is object *pop really doing after all this ?
thank you.