why can't we declare object of a class inside the same class?

后端 未结 6 702
礼貌的吻别
礼貌的吻别 2020-12-01 19:10
class A
{
  A a;//why can\'t we do this
};
6条回答
  •  Happy的楠姐
    2020-12-01 19:28

    This is the way you can have a pointer to object of class A and this way it is not required to know the size of class A before it is declared at compile time.

    class A {
    A* a;
    };
    

提交回复
热议问题