• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

How to embed CList<CMyClass, CMyClass&> as a member of CMyClass?

I am in the process of converting a std::vector based list to a CList.  Problem is that I have a class that needs to define a member that is a list of its own type (recursive).  Here's the pseudo code:

class CMyClass
{
public:
  CList<CMyClass, CMyClass&> m_cMyList;
};

  For the record, I can do this with std::vector, but I get error C2079: 'data' uses undefined class 'CMyClass' when I use CList.

  Now, I know that I could do this:

class CMyClass
{
public:
  CList<CMyClass*, CMyClass*&> m_cMyList;
};

  but I would have a TON of memory management code to write, as this is a very large project that this concept is heavily embedded in.

  Am I totally out of luck here, or is there some magical workaround that will get past the compiler errors?  Using Visual C++ 6.0 SP3.

  The reason I'm doing this is because of the problems we've been having with std::vector.  CList has been much more reliable for us, and we want all of our code to use that.

  Any and all help is much appreciated!!!  Thanks in advance!

Doug
0
DouglasHolt
Asked:
DouglasHolt
1 Solution
 
DouglasHoltAuthor Commented:
Hi all,

  I should have figured this out quicker, but anyway, here's the solution:

  std::vector is much closer to CArray than CList.  CArray doesn't have the problem I mentioned above.

  So, use CArray to replace std::vector, and it will work fine.

Doug
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now