This isn't working. And the reason why is cryptic to me.
PS: Using C++11
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
struct MyStruct {
size_t some_num;
char some_char;
bool some_bool;
MyStruct* some_ptr;
};
vector<vector<vector<MyStruct>>> three_d_struct_v;
size_t max_i = 100;
size_t max_j = 10;
size_t max_k = 10;
for(size_t i = 0; i < max_i; i++) {
for(size_t j = 0; j < max_j; j++) {
for(size_t k = 0; k < max_k; k++) {
three_d_struct_v.emplace_back(k, 'x', false, nullptr);
}
}
}
return 0;
}
Here,
three_d_struct_v
is of typevector<vector<vector<MyStruct>>>
, i.e. avector
ofvector<vector<MyStruct>>
, so you need to add element of typevector<vector<MyStruct>>
(likewise for nested dimensions). However, in your code, you are adding element of typeMyStruct
directly.You need to change to something like:
Check out ideone for the whole code.