我以前使用過TDM-GCC-5.10,現在切換回4.9 MINGW-GCC,並嘗試使用列表出現奇怪的錯誤-initialization:無法將{...}從<brace-enclosed initializer list>轉換爲結構
class Vector2
{
public:
Vector2(float x, float y)
{
this->x = x;
this->y = y;
}
float x = 0.f;
float y = 0.f;
};
struct Test
{
int x = 0;
Vector2 v;
};
int main()
{
Test tst = {0,Vector2(0.0f,0.0f)}; //Error
return 0;
}
錯誤:
main.cpp: In function 'int main()':
main.cpp:21:41: error: could not convert '{0, Vector2(0.0f, 0.0f)}' from '<brace-enclosed initializer list>' to 'Test'
Test tst = {0,Vector2(0.0f,0.0f)}; //Error
^
我用C++ 14與兩個編譯器。哪裏不對?
問題中沒有'main'。看[問]並提供[mcve]。 – Olaf
@Olaf編輯,只需複製並嘗試運行它。 –
回滾到以前的版本。如果該編輯刪除了該答案的上下文,則一旦有答案,就不應該編輯問題。你可以附加一個解釋,但如果明確標記爲這樣的話。 – Olaf