Reputation: 11082
I am trying to make class that has a member of type of it's enclosing class but I get an error saying field has incomplete type. here is an example
class List {
public:
List (int element, List rest) {
_first = element;
_rest = rest;
}
.
.
.
}
Is there a way to fix this problem?
Upvotes: 0
Views: 6669
Reputation: 272657
You haven't given us the complete definition of List
, but I'm guessing from your description that you have something like:
class List
{
...
List _rest;
};
Obviously, this is impossible. An object cannot contain a member of its own type, as this would lead to an infinite recursion!
Perhaps you want a member that is a pointer or a reference?
Upvotes: 5