我正在尝试创建一个包含以下类型的结构的类:
struct gameObject
{
int row; // row position of the object
int column; // column position of the object
bool isFound; // flag to indicate if the object has been found (or is dead, in the case of the monster)
bool isVisible; // flag to indicate if the object can be seen on the board -add in week 4
};
struct playerObject
{
bool alive; // flag to indicate if the player is alive or dead
bool hasWeapon; // flag to indicate if the player has the weapon
bool hasTreasure; // flag to indicate if the player has the treasure
bool hasTorch; // flag to indicate if the player has the torch -add in week 4
bool hasNoisemaker; // flag to indicate if the player has the noisemaker -add in week 4
bool hasKey;
gameObject position; // variables for row, column and visibility
};
我正在这样做,所以我可以将所有“游戏片段”和他们的数据放在一个对象下,以期有助于提高可读性。 我试图宣布的课程如下:
class pieces{//the class for the game and player objects
public:
pieces();
~pieces();
gameObjectType hold = EMPTY; // Holds objects under the monster<bug fix>
// </WK6>
playerObject player = { true, false, false, false, false, false, { -1, -1, false, true } }; // the player
gameObject treasure ={ -1, -1, false, true }; // the treasure
gameObject monster = { -1, -1, false, true }; // the monster
gameObject weapon = { -1, -1, false, true }; // the weapon
gameObject torch = { -1, -1, false, true }; // the torch
gameObject noisemaker = { -1, -1, false, true }; // the noisemaker
gameObject key = { -1, -1, false, true };
gameObject caveExit = { -1, -1, false, true }; // the cave exit
};
问题是我一直收到C2661错误。对于我的所有gameObject声明,它都说error C2661: 'gameObject::gameObject' : no overloaded function takes 4 arguments
但是,对于我的playerObject,它说的相同,除了7个参数而不是4个。
我已经好几个小时了,我无法弄清楚发生了什么。
答案 0 :(得分:-1)
如果你声明你的结构是这样的:
typedef struct gameObject {
{
int row; // row position of the object
int column; // column position of the object
bool isFound; // flag to indicate if the object has been found (or is dead, in the case of the monster)
bool isVisible; // flag to indicate if the object can be seen on the board -add in week 4
} gameObject;
然后我希望它一切顺利。请注意&#39;}&#39;
之后的gameObject