Hello,
I want to insert some My_Struct* pointers into a 2-dimensional array. In a 1-dimensional array, I normally do this by simply using the push_back function of a vector. But in 2-dimensions, this doesn't seem to work. Here is what I tried:
I want to create a 5 x 20 vector, with each element pointing to a My_Struct object. But when I try this approach, I get the error "vector subscript out of range" at the first push_back(x) call.Code:vector<vector<My_Struct*> > my_vector; for (int i = 0; i < 5; i ++) { for (int j = 0; j < 20; j ++) { My_Struct* x = new My_Struct(); my_vector.push_back(x); } }
How can I do this?
Thanks