ゲーム オブジェクトを制御するためのメイン クラスが「inGame」であるゲームを作成しています。「inGame」内に構成された他のいくつかのカスタムメイドのクラスがあります。
お気に入り、
class mouse
{
int x, y;
bool alive;
float speed;
public:
mouse(int xx, int yy, float spd, bool alv)
{
x = xx; y = yy; speed = spd; alive = alv;
}
// member functions
};
class inGame
{
mouse m1;
dog d1; // single object which are easy to construct
public:
inGame() : d1(200, 400, 1.5, false), m1(40, 40, 0.5, false) //This works fine
{} //coordinates fixed and set by me
// member functions
};
しかし今、私は 3 匹のマウスが欲しいとしましょう。だから私はm1 [3]またはおそらくベクトルを考えました。
class inGame
{
mouse m1[3]; // like i want 3 mouse(animals) in the game screen
dog d1; // single object which are easy to construct
public:
inGame() : d1(200, 400, 1.5, false) //Confusion here m1(40, 40, 0.5, false)
{}
// members
};
だから私は次のことを試しました:
inGame() : m1[0](1,2,3,true), m1[1](2,3,4,true), m1[2](3,4,5,true) { } //NO
inGame() : m1 { (1,2,3,true), (2,3,4,true), (3,4,5,true) } { } //NO
inGame() : m1 { (1,2,3,true), (2,3,4,true), (3,4,5,true); } { }
std::vector m1 を使用する場合でも、ゲーム内のデフォルト コンストラクターを使用して初期化する方法を教えてください。コンストラクター内に書いているでしょうか?
mouse temp(1,2,3,true);
m1.push_back(temp);
より良いアプローチはどれですか?主に私はただやります:
inGame GAME; //Just to construct all animals without user requirement
ありがとう。
アップデート:
運が悪い
inGame() : m1 { mouse(1,2,3,true), mouse(2,3,4,true), mouse(3,4,5,true) } { }
inGame() : m1 { {1,2,3,true}, {2,3,4,true}, {3,4,5,true} } { }
"m1 {" の後に "expected a )" というエラーがあります。そして m1 { "}<--" は ";" を期待していました