-
March 25th, 2004, 08:44 AM
#1
CList
Is it possible to declare a CList inside of a CList node?
CMyNode{
public:
int key;
CList<int,int> data;
};
CTest{
public:
CList<CMyNode,CMyNode> m_datalist;
};
This gives me a compile error. Does anyone know why?
-
March 25th, 2004, 08:47 AM
#2
what is the error message(s)?
The intelligent man finds almost everything ridiculous, the sensible man hardly anything.
- Johann Wolfgang von Goeth
-
March 25th, 2004, 08:59 AM
#3
Re: CList
Originally posted by mps2
Is it possible to declare a CList inside of a CList node?
CMyNode{
public:
int key;
CList<int,int> data;
};
CTest{
public:
CList<CMyNode,CMyNode> m_datalist;
};
This gives me a compile error. Does anyone know why?
This has been discussed many times on CodeGuru. CList has no copy constructor, and the items that can go in the CList must be copyable and assignable.
For example, you will get a compiler error if you do this:
Code:
void foo()
{
CList<int, int> L1;
CList<int, int> L2 = L1; // error
CList<int, int> L3;
L3 = L2; // error
}
Creating copies and assigning are some of the operations that CList does internally with the type. The program above shows that copying and assinging CList's are illegal.
To get around the problem,
1) Use pointers to CList OR
2) Derive from CList and provide your own copy ctor and assignement operator OR
3) Use std::list<T> instead of CList. std::list is copyable without adding any code.
Regards,
Paul McKenzie
-
March 25th, 2004, 01:21 PM
#4
thanks...i used the std::list
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|