我有以下合成代码。它会产生错误,
#include <iostream>
using namespace std;
class X
{
private:
int iX;
public:
X(int i=0) : iX(i) { cout <<"Constructing X.."<<endl; }
~X() { cout <<"Destructing X.."<<endl; }
int getIX() { return iX; }
};
class Y
{
private:
X x(3);
int jY;
public:
Y(int j = 0) : jY(j) { cout <<"Constructing Y.."<<endl; }
~Y() { cout <<"Destructing Y.."<<endl; }
void callGetX() { cout <<"iX is "<<(x.getIX())<<endl; }
};
int main()
{
Y yObj(1);
yObj.callGetX();
}
错误:在成员函数 void Y::callGetX() 'x' 中未声明(首先使用此函数)
有什么我错过的吗?谁能告诉我这个场景的构造函数调用机制?