2016-12-16 1071 views
1

我试图创建一个包含以下类型的结构类: C++错误C2661:没有重载函数采用X参数

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错误。对于所有的游戏对象我的声明,它说error C2661: 'gameObject::gameObject' : no overloaded function takes 4 arguments 但是,对于我的playerObject,它说同样动作,除了7个参数,而不是4

我一直盯着它几个小时,我想不通这是怎么回事。

+2

这是什么版本的VS? –

+0

它的版本是2013. –

+3

由于[编译器错误],您尝试使用的语法(非静态数据成员的限定列表初始化)不适用于MSVC2013(https://connect.microsoft.com/VisualStudio /反馈/信息/ 792161 /构造函数初始化列表 - 不 - 不支持 - 支撑 - 初始化列表形式)。但是,VS2013更新3应该修复了它 - 您是否拥有Visual Studio安装的最新更新? – birryree

回答

-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; 

然后,我希望它会所有的工作。注意'}'后面的gameObject

+0

我试过了,但它没有工作=( –

+0

有趣的是,在VS2013中,我运行代码时得到了这个错误:错误C2797:'pieces :: player':列表初始化在成员初始化器列表或非静态数据成员初始化器中没有实现 –

+0

似乎@ birryee是正确的:https://blogs.msdn.microsoft.com/somasegar/2013/06/28/c-conformance-roadmap/ –

相关问题