I saw several places (e.g) where 2-dim vector can be initialized like this
vector<vector<int> > vec(3, vector<int>(2, 0));
What I am thinking is that this code is evaluated to following
auto tmp = vector<int>(2, 0);
vector<vector<int> > vec(3, tmp);
If I am correct, then 3 elements of vec
all refer to a same reference.
Which means that modifying vec[0][1]
also modifies vec[1][1]
.
If I am wrong, how does C++ make the initialization of each element in vec
be a different reference?