Hey guys, how do i make a constructor/ destructor to a class inside a class?
for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
h.file
class MonomList{
private:
class Node{
public:
Monom *mon;
Node *next;
Node *prev;
};
Node *head;
Node *tail;
};
end of h.file
this is my class, how can i make a constructor to Node?
Nice basic solution Peter87.
Of course, I must go overboard.
Having a Monom* as a data member in the Node suggests polymorphic storage (else why not store a Monom instance), which in turn suggests having a virtual clone() method returning a pointer to a new Monom object of the appropriate type (as a copy). While we're at it, why not establish all linkage within the list as well?
> Having a Monom* as a data member in the Node suggests polymorphic storage
> (else why not store a Monom instance)
Because you are not responsible of the lifetime.
Because you don't want to work with a copy.
(use a smart pointer to resolve node copies and validity of access to mon)