4D vector problem

Tryed to create this vector but i keep getting this error

1
2
3
4
5
6
7
#include <vector>
using namespace std;

int main(){

    vector<vector<vector<vector<int>>>> vec(100, vector<int>(200, vector<int>(100, vector<int>(50))));
}

Error	1	error C2665: 'std::vector<int,std::allocator<_Ty>>::vector' : 
none of the 10 overloads could convert all the argument types


Of course list of error is even longer but maybe someone will know why its not working?
Last edited on
You provide the wrong type:

1
2
3
4
5
6
7
#include <vector>
using namespace std;

int main(){

    vector<vector<vector<vector<int>>>> vec(100, vector<vector<vector<int>>>(200, vector<vector<int>>(100, vector<int>(50))));
}
The second argument to the vector<vector<vector<vector<int>>>> constructor should be a vector<vector<vector<int>>>,

and the second argument to the vector<vector<vector<int>>> constructor should be a vector<vector<int>>.
A "4D" vector is made of a list of 3D vectors, which has a list of 2D vectors, which has finally a list of regular vectors.
Your outermost constructor is currently only supplying 100 1D vectors, when it should be supplied 100 3D vectors.

Note the differences:
1
2
3
4
5
6
7
8
9
10
11
    #include <vector>
using namespace std;

int main(){

    vector<vector<vector<vector<int>>>> vec(100, vector<vector<vector<int>>>
                                           (200, vector<vector<int>>
                                           (100, vector<int>
                                           (50))));
                                            // separated to see each inner dimension
}

Darn I was beat to it.
Last edited on
TY guys for all your help :) Really appreciate it :)
Topic archived. No new replies allowed.