When you delete a VectorNode
that has its t_next
member pointing to some other node, the destructor of VectorNode
will delete that other node (which in turn might go on to delete further nodes).
When you remove a node from the middle of a list with Remove()
, the t_next
of this node will point to the further nodes of the list. When this node is deleted, the destructor will also delete all the nodes following it in the list. Continuing to use this half-deleted list it will result in all kinds of problems.
Other random observations:
- Why is
size
a int*
instead of a normal int
or size_t
? I can't see any reason why this should be a pointer.
new VectorNode<var>(*(new var))
should really be new VectorNode<var>(var())
to not unnecessarily leak memory.
- The
t_next != NULL
test before delete
is unnecessary
- Are you planning to create classes deriving from
VectorNode<>
? If not, than there is no reason why the methods would need to be virtual
.
- Using 1-based indexing in
Add()
is unusual, one would expect zero-based indexing
Also I feel obliged to tell you that there are standard library containers like std::list<>
and std::vector<>
which implement this kind of structures.