It's very clear that row major form of a 2D array is a single array stored such that different rows are aligned in sequence.
To traverse any element of the 2d array I can always do :
int a[3][3]={{1,2,3},{4,5,6},{7,8,9}};
for(int i=0;i<3*3;i++){
cout<<*(*a+i)<<" "; //row major form concept where i<m*n;
}
gives:
1 2 3 4 5 6 7 8 9
It completely works for me but whenever I do this with a vector it throws me an error:
vector<vector<int> > v={{1,2,3},{4,5,6},{7,8,9}};
int m=v.size();
int n=v[0].size();
for(int i=0;i<m*n;i++){
cout<<*(*v+i)<<" ";
}
It gives :
no match for ‘operator*’ (operand type is ‘std::vector<std::vector<int> >)
I hope that vectors do follow the row major form concept as arrays. If yes than what is alternative for row major in case of a vector?