I was looking at one of the answers on Stack Overflow to create a class for a 2d Vector. The solutions involved initialising the inner vector while the outer vector was being created.
class A{
public:
A(int dim1,int dim2):v(dim1,std::vector<int>(dim2)){}
private:
std::vector< std::vector<int> > v;
};
class A{
public:
A(int dim1,int dim2){v.resize(dim1,std::vector<int>(dim2));}
private:
std::vector< std::vector<int> > v;
};
I understood that a vector can be initialised like this
size=4; value =10; std::vector<int> A (size,value);
However I dont have an intuitive sense as to how can a vector be initialised like std::vector (size), with the variable object absent, as is happening while setting dim2 in the initial code snippet. Am I missing something?