c++ error:cannot define member function 'X::show' within 'Y' 是怎么回事?

c++ error:cannot define member function 'X::show' within 'Y' 是怎么回事?

问题描述:

图片说明图片说明

这…………
你不能在Y中定义X类的成员变量,因为Y和X没有任何关系。
除非Y继承自X,才能继承或重载X的成员函数。

class Y: pubilc class X 
{
}

或者Y里有X实例或指针作为其成员。

class Y{
public:
    X* px;
}