0

I'm porting to a recent MSVS version the code that somehow compiled in MSVC++ 6:

class CTreeNode;

typedef std::deque<CTreeNode> TTreeNodes; 

class CTreeNode {
    // ...
    TTreeNodes   succNodes;
    // ...
};

However, in recent MSVC++ this code doesn't compile with error C2027: use of undefined type 'CTreeNode' at the line containing TTreeNodes succNodes;.

Any ideas how to change the code least intrusively so to make it to compile?

Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158
  • You need to use *pointers*. Otherwise you have a structure which contains itself which contains itself which contains itself... And so one in all infinity. – Some programmer dude Oct 22 '18 at 09:08
  • 3
    @Someprogrammerdude But a deque uses pointers internally. – interjay Oct 22 '18 at 09:13
  • Yup, confirmed failing on MSVC https://godbolt.org/z/KeZzKg – StoryTeller - Unslander Monica Oct 22 '18 at 09:16
  • Related: https://stackoverflow.com/questions/18672135/why-c-containers-dont-allow-incomplete-types. Boost.container library has a deque that supports incomplete types. – interjay Oct 22 '18 at 09:23
  • @interjay That is very implementation-specific (but also very likely). However the deque still need to store `CTreeNode` *objects* inside itself somehow. Usually it keeps a list of arrays of *objects*. – Some programmer dude Oct 22 '18 at 10:09
  • Something wrong with just declaring `std::deque succNodes;` ? – WhozCraig Oct 22 '18 at 10:28
  • @Someprogrammerdude And then the list inside the deque will store pointers. The deque doesn't store objects directly. As I said above, the Boost.Container library does have containers (including deque) that support recursive types but unfortunately the C++ standard doesn't require this. – interjay Oct 22 '18 at 10:35

0 Answers0