Sign in to follow this  

Error: 'ListT::next' has incomplete type

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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"...

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this