How to create multidimensional multitype c++ vector? -


i'm looking way create c++ vector hold class object ( multi dimensional array - 3d coordinate system location mapper ) , int object describes in way.

i have found many examples of multidimensional single type vectors like

vector <vector<int>> vec (4, vector<int>(4)); 

i need dynamic structure can grow/shrink in heap time progress flexibility of vector type.

// position object, whatever declaration may struct position { int x, y, z; };  struct connection {     position position;     int strength; };  // want node class // based on comment gave. struct node {     position position;     std::vector<connection> connections; };  // vector dynamic , resizable. // use std::vector::push_back , std::vector::emplace_back methods  // insert elements @ end, , use resize method modify  // current size , capacity of vector. std::vector<std::vector<std::vector<node>>> matrix; 

an alternative define connection std::pair<position, int>, wouldn't because if wanted add more information connection in future, you'd have change more code should.

if want resize whole multidimensional array, you'll have iterate on vectors 1 one loop , call resize method.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -