I am trying to initialize a pointer (*vectorName) with a 2D vector 366 by 4.
Both
vector<int> *vectorName = new vector<int>(366, new vector<int>(4));
and
vector<int> *vectorName = new vector<int>(366, vector<int>(4));
do not work and give me the error
Error: no instance of constructor “std::vector, <_Ty, _Alloc>::vector [with_ty=int, _Alloc=std_allocator]”
argument types are (const int, std::vector>*)
What can I do?
This is happening within the main function.
The above doesn’t work because the vector constructor template (ignoring a few things) looks as follows:
And in
vector<int>(366, vector<int>(4)),vector <int> (4)is not of typeint.To create a
vectorwith 366 elements that arevectorofints of size 4:or, if you don’t need a pointer: (which you quite possibly don’t)
As a side note, if it’s a fixed size 2D
vector, why are you usingvector, and not just an array. This would be much simpler: