我无法理解何时以及如何在C++ 11中使用新的统一初始化语法.
例如,我得到这个:
std::string a{"hello world"}; // OK
std::string b{a}; // NOT OK
Run Code Online (Sandbox Code Playgroud)
为什么在第二种情况下不起作用?错误是:
error: no matching function for call to ‘std::basic_string<char>::basic_string(<brace enclosed initializer list>)’
Run Code Online (Sandbox Code Playgroud)
使用此版本的g ++ g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2.
对于原始数据,我应该使用什么语法?
int i = 5;
int i{5};
int i = {5};
Run Code Online (Sandbox Code Playgroud)