我有问题。我想从类“Game”中调用“gameWindow”的构造函数。问题是,如果我从构造函数调用它作为局部变量初始化(示例A),如果我将它定义为私有成员 - 我不能使用构造函数的参数。我如何使gamewindowObj作为构造函数的成员?如何使用构造函数的参数来调用C++中另一个类的构造函数?
//例如А
class Game{
public:
Game(int inWidth, int inHeight, char const * Intitle);
};
Game::Game(int inWidth, int inHeight, char const * Intitle){
gameWindow gamewindowObj=gameWindow(inWidth, inHeight, Intitle);
}
//例如В
class Game{
public:
Game(int inWidth, int inHeight, char const * Intitle);
private:
gameWindow gamewindowObj=gameWindow(inWidth, inHeight, Intitle);
};
Game::Game(int inWidth, int inHeight, char const * Intitle){}
使用构造函数初始化列表:'游戏(INT inWidth,....):gamewindowObj(inWidht,...){}' – user463035818