I want to create two and three dimensional vectors using a constructor in a class. However, I do not know how for multidimensional vectors.
One dimensional works:
class One{
public:
vector < float > myvector;
One(int length) : myvector(length){}
};
Two dimensional does not work:
class Two{
public:
vector < vector < float > > myvector;
Two(int length, int width) : myvector(length)(width) {}
};
Three dimensional does not work either:
class Three{
public:
vector < vector < vector < float > > > myvector;
Three(int length, int width, int height) : myvector(length)(width)(height) {}
};
The answer below works for two dimensional vector. I would expect the following code for three dimensional however it seems to be wrong
class Three{
public:
vector < vector < vector < float > > > myvector;
Three(int length, int width, int height) : myvector(length, vector<float>(width, vector<float>(height))) {}
};