in my mind, I want to gather all objects T at the matrix to some local one-dimensional vector and return the iterator.begin to this vector
That would imply copying the whole matrix. A big no-no. Not only because of the time of the copying, the effective doubling of space, but also because you would have elements duplicated in two locations. When one it's modified the other retains the old value.
You have two options:
Flatten the matrix storage
template <class T>
class myClass{
vector<T> matrix;
T& get(size_t line, size_t column)
{
return matrix[line * columns_count + column];
}
};
This is good for two reasons: better cache locality and easy to implement iterators:
using ConstIterator = std::vector<T>::const_iterator;
ConstIterator cbegin() const { return matrix.cbegin(); }
Implement the iterator
If you want to keep the 2dim storage then you need to implement the iterator. It's a little too much boilerplate for my taste, so I will give you just a guidance to get you started if you wish to go this route:
The iterator should keep an pointer/reference to the matrix, a pointer/reference/index to the current line and one to the current column. On ++
operation go next on the column and if you reached the end of the column then increase the line and reset the column.