开发者

field has incomplete type C++

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?


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?


Use this:

'rest' should be a pointer to a List.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜