Home > other >  3 dimensional vector in c
3 dimensional vector in c

Time:06-05

i want to store a vector of objects for a node and subset of set. so I want to implement a 3 d vector where the first dimension has size #nodes = n and the second dimension has size 2^|set| = m. the last dimension shouldn't have fixed size, because I want to append new objects in my program.

vector< vector < vector<Object>>> Vector3d( n , ( m, ( ( ???)))

what should I write instead of ???

i have tried to use arrays inside of a vector, but I didn't succeed that way.

thank you in advance

CodePudding user response:

The method of initialisation is

vector< vector < vector<Object>>> Vector3d(n,vector<vector<Object>(m))

This will work, as it will initialize the first dimension's size as n, which would contain n no of vector<vector<Object>(m) which is the default value. Now the size of the second dimension is defined as m, which has no initial value, hence you can append any vector to the second dimension space.
i.e.

vector<Object> v;
Vector3d[i][j].push_back(v);

where i and j are the indexes of the first 2 dimensions

  • Related