I need to declare the number of vectors according to an input parameter call NUM HOST.
for example, if NUMHOST=4, I need to declare 4 vectors and the name of the vectors seriam: vector1, vector2, vector3, in struct for would be vectori...
for (int i = 0; i <= NUMHOST; i++)
int vector????[3];
Yeah, store the vectors in a vector. But you don't have to use a loop.Instead you can pass the size of the vector to the constructor. std::vector<std::vector<YourClass>> v(NUMHOST);
I believe that I can not use vector of vectors because I'm programming a distributed system and each node should only be aware of your information and not the information global network, so I have to have a vector only.
It should not matter, as long as you don't share information that is not necessary.
1 2 3 4 5 6 7 8 9 10 11 12
int do_something_to_a_vector( std::vector <int> & v )
{
// this function only knows about v
}
int main()
{
// The list of vectors
std::vector <std::vector <int> > vs( n );
...
do_something_to_a_vector( vs[ 2 ] );
...
std::vector <std::vector <int> > vs( n );
creates a vector of n empty vectors. These vectors must be populated before you can access elements of those vectors.
std::vector<std::vector<int>> vs(n, std::vector<int>(m))
creates a vector of n vectors of m elements.