Public Group

# Error: 'ListT::next' has incomplete type

This topic is 3629 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

template <class T> class List{ public: T value; bool empty; List<T> next; //This is where the error occurs! List<T>(){ empty = true; } public: T Get(int index){ if (index==0) return value; else next.Get(index-1); } public: void Append(T valuepar){ if (empty){ value = valuepar; next = List<T>(); } else{ next.Append(valuepar); } } }; class Location{ public: int x,y,z; int Get(Cor c){ switch (c){ case X: return (*this).x; break; case Y: return (*this).y; break; case Z: return (*this).z; break; } } Location operator= (Location loc){ x = loc.x; y = loc.y; z = loc.z; return *this; } Location(){ x = 0; y = 0; z = 0; } Location(int parx, int pary, int parz){ x = parx; y = pary; z = parz; } Location move(sixDirection direction){ switch (direction){ case Xup: return Location(x+1,y,z); break; case Xdown: return Location(x-1,y,z); break; case Yup: return Location(x,y+1,z); break; case Ydown: return Location(x,y-1,z); break; case Zup: return Location(x,y,z+1); break; case Zdown: return Location(x,y,z-1); break; } } void SetCube(bool used){ Cubes[x][y][z] = used; } bool GetCube(){ return Cubes[x][y][z]; } void Set(Shape,Cor); }; List<Location> XBeamList; What's the problem? THanks

##### Share on other sites
You've done the moral equivalent of :
struct A {  A something;};

In other words, your list contains a list, which will contain a list, which will contain a list, etc. etc.

You probably want next to be a List<T> pointer.

##### Share on other sites
To remove all the unnecessary clutter, consider this equivalent code:
struct X { X next; };

Since X has a member of type X, it means that to construct an object of type X one must first start by constructing its member object of type X. This is an infinite recursion, which the compiler simply refuses.

You probably wanted to use a pointer, reference or smart pointer there.

EDIT: not only did SiCrane say the exactly the same thing, but he also said it using the same paragraph structure, "equivalent" and "You probably want"...

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 10
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631751
• Total Posts
3002087
×