VC++ 2013 Initializer List issue

走远了吗. 提交于 2019-12-12 02:32:19

问题


I've the following code that doesn't compile with vc++ 2013. Is it a compiler bug?

class Test
{
public:
    Test() :
        mTestBuff{ 1, 2, 3, 4 }
    {

    }

private:
    const vector< int > mTestBuff;
};

error C2661: 'std::vector<int,std::allocator<_Ty>>::vector' : no overloaded function takes 4 arguments

This compile fine with GCC 4.8 and MinGW. What can I done to remove the compile error?


回答1:


Try this:

Test() :
    mTestBuff({ 1, 2, 3, 4 })
{

}

Demo here.



来源:https://stackoverflow.com/questions/21533191/vc-2013-initializer-list-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!