I want to build a simple matrix class. The relevant part of my header file looks like this:
template <typename T>
class matrix
{
private:
unsigned int nrows;
unsigned int ncols;
std::array<std::array<T, ncols>, nrows> mat;
public:
matrix();
unsigned int getCols() const;
unsigned int getRows() const;
};
The problem here is that the two-dimensional array (called mat) needs the number of rows and columns. Obviously, this doesn't work but I don't know how to solve this issue.
My source file:
template <typename T>
matrix<T>::matrix() : nrows(0), ncols(0) {}
template <typename T>
unsigned int matrix<T>::getCols() const {
return ncols;
}
template <typename T>
unsigned int matrix<T>::getRows() const {
return nrows;
}
The initialization of a matrix should look something like this:
matrix<double> my_matrix;
std::vector<std::vector>std::array<std::array>dimensions must be known at compile time.