2015-11-02 20 views
1

我的新班級名爲Fountainofyouth出現了問題。努力打造整個項目調試後顯示預計{before destructor

warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default] 

和 錯誤:expected '{' before 'Fountainofyouth' 誰能告訴我怎麼回事? 內容Fountainofyouth.cpp的:

#include "Fountainofyouth.h" 

//warning 
Fountainofyouth::Fountainofyouth(int startDrinks) : Field 
{ 
    //ctor 
} 

//error 
Fountainofyouth::~Fountainofyouth() 
{ 
    //dtor 
} 

string Fountainofyouth::fieldType() 
{ 
    return 0; 
} 

bool Fountainofyouth::canEnter(Unit* unit) 
{ 
    return 0; 
} 

void Fountainofyouth::affect(Unit* unit) 
{ 

} 

`

+0

這將有助於瞭解什麼是'Field'。 – skypjack

回答

4

構造函數定義不應該有: Field部分:

Fountainofyouth::Fountainofyouth(int startDrinks) // : Field <- remove this 
{ 
    //ctor 
} 

如果你的意思是繼承FountainofyouthField那麼在這樣做類的定義,而不是它的構造函數。

struct Fountainofyouth : Field 
{ 
    // declaration of ctor, dtor, etc. 
}; 

另外,如果FieldFountainofyouth然後value initialize成員添加一對括號它:

Fountainofyouth::Fountainofyouth(int startDrinks) : Field() 
{ 
} 
+4

或者,如果'Field'是一個試圖默認構造的變量,它應該是:'Fountainofyouth(int startDrinks):Field(){}' – Tas

+0

添加了這些數據,謝謝! – legends2k