The following generates error:
int main() {
mat_int mat1(5, vector<int>{1,2,3});
mat_int mat2(5, vector<int>{4,5,6});
for (auto it1 = mat1.begin(); it1 != mat1.end() ; ++it1) {
for (auto it11 = *it1.begin(); it11 != *it1.end(); it11++)
cout << *it11;
cout << '\n';
}
}
Compiler doesn't accept the inner loop iterators; /home/asabbah/programming/C++/vectors1.cpp:16:28: error: ‘class __gnu_cxx::__normal_iterator*, std::vector > >’ has no member named ‘begin’
However, if I insert a temp variable:
vector<int> temp = *it1;
then:
for (auto it11 = temp.begin(); it11 != temp.end(); it11++);
everything goes fine.
Any idea why is this so?