我試圖創建一個包含以下類型的結構類: 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
我一直盯着它幾個小時,我想不通這是怎麼回事。
這是什麼版本的VS? –
它的版本是2013. –
由於[編譯器錯誤],您嘗試使用的語法(非靜態數據成員的限定列表初始化)不適用於MSVC2013(https://connect.microsoft.com/VisualStudio /反饋/信息/ 792161 /構造函數初始化列表 - 不 - 不支持 - 支撐 - 初始化列表形式)。但是,VS2013更新3應該修復了它 - 您是否擁有Visual Studio安裝的最新更新? – birryree