CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: CList

  1. #1
    Join Date
    Aug 2000
    Posts
    110

    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?

  2. #2
    Join Date
    Mar 2004
    Location
    Belem - Brazil
    Posts
    25
    what is the error message(s)?
    The intelligent man finds almost everything ridiculous, the sensible man hardly anything.
    - Johann Wolfgang von Goeth

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    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

  4. #4
    Join Date
    Aug 2000
    Posts
    110
    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
  •  





Click Here to Expand Forum to Full Width

Featured