Archived

This topic is now archived and is closed to further replies.

Nickels

deleting template datastructures

Recommended Posts

i made a template linked list. situation 1) i use it to hold Node''s. situation 2) i use it to hold Node*''s. How can i handle the destructor? should i just make 2 functions, one to simply delete the listnodes, and another to delete the Node* and then the linknodes?

Share this post


Link to post
Share on other sites
You want Full Value Semantics. You store Nodes with contain a copy of the data. This way the use can decide if they want to use pointers or not, among other benefits. When a node is deleted, it''s data will be deleted automatically then.


template<typename T>
struct List
{
struct Node
{
Node* next;
Node* prev;
T data;
};
Node* head;
Node* tail;
};

Share this post


Link to post
Share on other sites