我之前使用过TDM-GCC-5.10,现在切换回4.9 MINGW-GCC并尝试使用列表初始化时遇到奇怪的错误:
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;
}
Run Code Online (Sandbox Code Playgroud)
错误:
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
^
Run Code Online (Sandbox Code Playgroud)
我在两个编译器中都使用了C++ 14.怎么了?