Jump to content
  • Advertisement

Archived

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

Nickels

deleting template datastructures

This topic is 5374 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!