Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant initialize a std array into a std vector

Tags:

c++

c++11

Not an actual problem but rather a fashion crisis..

 vector<array<unsigned int, 3>> tri;
 tri.push_back(array<unsigned int, 3> {0, 0, 0});

gives me a syntax error. Is there any way to initialize a std array with values into a vector in one line?

like image 378
Jake Freelander Avatar asked Nov 20 '25 18:11

Jake Freelander


1 Answers

The first rule of std::array is: when in doubt, add more braces. That's because you're actually initializing the raw array subobject of the std::array.

tri.push_back(array<unsigned int, 3> {{0, 0, 0}});

Both GCC and Clang accept this statement.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!