I have a Matrix class template as follows:
template
class Matrix
{
T data[nrows][ncols];
public:
skypjack and max66 have both presented simple answers to the problem. This is just an alternate way of doing it, using simple inheritance, although it means the use of a child class for square matrices:
template
class Matrix
{
protected:
T data[nrows][ncols];
public:
T& operator ()(std::size_t i, std::size_t j)
{
return data[i][j];
}
};
template
class SqMatrix : public Matrix
{
public:
setIdentity()
{
//Do whatever
}
}