I am implementing a Matrix
with a generic vector of generic vectors (vector<vector<T>>
).
My constructor receives a vector of vectors and initializes the data member using the CCTOR the library provides. When I am trying to initialize the matrix with aggregate initialization, the following line of code works:
Matrix<int> mat({ {1, 2, 3} });
But the next one doesn't:
Matrix<int> mat({ {1, 2, 3}, {4, 5 ,6} });
There is no error. Just a seemingly infinite loop.
I am clearly missing something here. What is my mistake?
Here is my matrix definition:
template<class T>
class Matrix {
private:
int _height;
int _length;
vector<vector<T>> _val;
public:
Matrix(vector<vector<T>> val) throw (const char*) :_height(val.size()), _length((*val.begin()).size()), _val(val) {
// Checking if the rows are of different sizes.
vector<vector<T>>::iterator it = val.begin();
it++;
while (it != val.end()) {
if ((*it).size() != _length) {
throw "EXCEPTION: Cannot Create Matrix from Vectors of Different Sizes.";
}
}
}
}
There is also an output function, but I don't think that has anything to do with it.