Search code examples
c++c++11stdvectorinitializer-liststd-pair

C++11 vector with two GLfloats as pair fail to uniform initialize


The error message of gcc 4.9.2 is:

could not convert from '<brace-enclosed initializer list>' to 'std::vector<std::pair<float, float> >'

of this code:

vector<pair<GLfloat, GLfloat>> LightOneColorsPairVec {{0.5f, 0.5f, 0.5f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f}};

The code is compiled with 'std=c++11' compiler flag.


Solution

  • First of all because std::pair doesn't have constructor that takes a std::initializer_list. Secondly because std::pair is a pair, it only have two values, not four.