I have the following:
#include
#include
And when I try to compile, I get the following error:
g++ -std=c++11 -Wall -pedantic ./test.cpp
./test.cpp:6:49: error: no matching constructor for initialization of 'std::vector >' (aka
'vector, allocator >, double> >')
std::vector> data = {{"close", 14.4}, {"close", 15.6}};
Answer
You need an extra pair of braces for each element/pair:
std::vector> data = {{{"close", 14.4}}, {{"close", 15.6}}};
^ ^ ^ ^
The extra pair of braces is needed because std::map
elements are of type std::pair
in your case std::pair
. Thus, you need an extra pair of braces to signify to the compiler the initialization of the std::pair
elements.
No comments:
Post a Comment