出于某种原因,我认为C++ 0x允许std::initializer_list作为函数的函数参数,例如,期望可以从这样构造的类型std::vector.但显然,它不起作用.这只是我的编译器,还是永远不会起作用?是因为潜在的重载解决问题吗?
#include <string>
#include <vector>
void function(std::vector<std::string> vec)
{
}
int main()
{
// ok
std::vector<std::string> vec {"hello", "world", "test"};
// error: could not convert '{"hello", "world", "test"}' to 'std::vector...'
function( {"hello", "world", "test"} );
}
Run Code Online (Sandbox Code Playgroud)