For example:
#include<vector>
using namespace std;
int main()
{
vector<int[]> vec;//serious compiler error
vector<int[2]> vec={{1,2}};//error:array must be initialized with a brace-enclosed initializer
}
In addition, how to rectify the grammar of the second one? I already use a brace-enclosed initializer.
It's not a variable-length array, those do not exist in C++. It's an array without a size specifier, an incomplete type that doesn't meet the requirements of most (all?) vector operations.
The second attempt tries to copy c-arrays (list initialization always does copying), and that too is not supported.
If you want a vector of arrays, spell it as std::vector<std::array<int, 2>>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With