Template problem...
I''m using templates for a link list. I''m using this link list for organising vertex indexes to CWnd''s.
The problem I have is that when I destroy the LinkList, I destroy(delete) the nodes (or links) of course and have an option to delete the node''s pointer which could be the CWnd or the vertex index etc.
Now when I delete the Node''s template class (any class), it sends me directly to the link list''s class.
this is my declaration for the link list
template class LINKLIST1D
{
public:
LINKLIST1D() { Head = NULL; DeleteNodes = FALSE;};
LINKLIST1D(bool mDeleteNodes) { Head = NULL; DeleteNodes = mDeleteNodes;};
~LINKLIST1D();
struct LINK
{
LINK() { Node = NULL; Next = NULL; };
T* Node;
LINK* Next;
};
LINK* Head;
bool DeleteNodes;
bool Add (T *Node);
bool Remove (T *Node, bool DeleteNode = FALSE);
void Empty();
};
typedef LINKLIST1D::LINK LINK1D;
So I create the linkList
LINKLIST1D CWndList;
I then add a node
CWnd* Window = new CWnd;
CWndList.Add(Window);
then when I destroy the class, I destroy all the new links I created and if needed, I need to delete the actual link''s node (the CWnd* window) that I passed through.. but it thinks I''m deleting a LINKLIST1D class and sends me to the destructor again
what am I doing wrong...
Well, from my experience (unless in Windows Programming there is a new way to work with templates), your notation seems a little off. When I used them, this is how I did it:
?? Maybe that will help you a little?! Not sure.
Mihkael
Edited by - Mihkael on August 3, 2000 11:38:28 PM
Edited by - Mihkael on August 3, 2000 11:39:20 PM
template <Class T> class LinkedList{public: LinkedList() {Whatever = whatever; etc = etc;} T& DoSomething();private: T TVariable;}template <Class T>T& LinkedList<T>::DoSomething(){ return TVariable;}Then, to create an instance, you do:LinkedList<int> MyLList;
?? Maybe that will help you a little?! Not sure.
Mihkael
Edited by - Mihkael on August 3, 2000 11:38:28 PM
Edited by - Mihkael on August 3, 2000 11:39:20 PM
You could also use the STL
std::list is probably what you''re interested in.
Of course, it is always good to understand how to make a template.
std::list is probably what you''re interested in.
Of course, it is always good to understand how to make a template.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement