此代码无法使用gcc(7.1)进行编译,但可以使用vc:
WebSocket
错误:
void f(const std::vector<std::string>&);
void test()
{
const auto strings = {std::string{"a"}, std::string{"b"}, std::string{"c"}};
f(strings);
}
如果我在In function ‘void test()’:
error: invalid initialization of reference of type ‘const std::vector<std::__cxx11::basic_string<char> >&’ from expression of type ‘const std::initializer_list<const std::__cxx11::basic_string<char> >’
f(strings);
^
note: in passing argument 1 of ‘void f(const std::vector<std::__cxx11::basic_string<char> >&)’
void f(const std::vector<std::string>& strings)
^
之前也删除了const
,则gcc也很高兴。这是gcc中的错误还是vc(VS 2017)的行为不正确?