stl - Initializing an array of pair in C++ -
i want initialize array of pair in next way:
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}};
however compiler, code::blocks 12.1, keeps on throwing error:
brace-enclosed initializer used initialize `std::pair<int, int>'|
i used method 1 time before on online compiler , worked. problem compiler or syntax issue in code? don't want initialize 4 pair 1 one. suggest way in can rid of error.
thanks help in advance.
this universal initialization syntax c++11 feature, compiler using not back upwards c++11 online 1 did.
you can initialize array instead:
pair<int, int> adjs[4] = {make_pair(current_node.first-1, current_node.second), ...};
a live example: http://ideone.com/ggpgx9
c++ stl compiler-errors pair
No comments:
Post a Comment