C++same class as member in class

后端 未结 3 847
轮回少年
轮回少年 2020-12-21 13:53

I have a class that should have a class of the same type as its member.

My declaration is the following:

class clsNode
{
private:
     clsNode m_Moth         


        
3条回答
  •  渐次进展
    2020-12-21 14:51

    When you have a member of a class type (directly not a pointer), the instance of your mother class contains physically the contained instance.

    In this case, the compiler can't find the size of the clsNode class as there's a cycle. It should contain a clsNode, which should contain a clsNode, and so forth.

提交回复
热议问题