use*_*557 7 c++ stl compiler-errors
我想以下列方式初始化一对数组:
pair<int, int> adjs[4] = {{current_node.first-1, current_node.second}, {current_node.first+1, current_node.second}, {current_node.first, current_node.second-1}, {current_node.first, current_node.second+1}};
Run Code Online (Sandbox Code Playgroud)
但是我的编译器Code :: Blocks 12.1继续抛出错误:
brace-enclosed initializer used to initialize `std::pair<int, int>'|
Run Code Online (Sandbox Code Playgroud)
我曾经在网上编译器上使用过这种方法,但它确实有效.那么编译器的问题还是我的代码中的一些语法问题?我不想一个一个地初始化4对.建议一种方法,我可以摆脱这个错误.
在此先感谢您的帮助.
mat*_*ort 16
这种通用初始化语法是C++ 11的一个特性,可能你使用的编译器不支持C++ 11,但在线编译器却支持C++ 11.
你可以这样初始化你的数组:
pair<int, int> adjs[4] = {make_pair(current_node.first-1, current_node.second), ...};
Run Code Online (Sandbox Code Playgroud)
一个实例:http://ideone.com/ggpGX9