Why I can't desalinize std::array like this?
#include <array>
struct Point
{
float x;
float y;
};
int main()
{
std::array<Point, 3> m_points {
{ 1.0f, 1.0f },
{ 2.0f, 2.0f },
{ 3.0f, 3.0f }
};
}
Doing this I get error:
error: too many initializers for
std::array<Point, 3ul>
but it works like this:
std::array<Point, 3> m_points {
Point{ 1.0f, 1.0f },
Point{ 2.0f, 2.0f },
Point{ 3.0f, 3.0f }
};
In contrast std::map
can be initialized with both ways written below:
std::map<int, int> m1 {std::pair<int, int>{1,2}, std::pair<int, int>{3,4}};
std::map<int, int> m2 {{1,2}, {3,4}};