I am trying to write an output function for a matrix class by overloading the operator<<
overload. The matrix class also has an indexing function, which is created by overloading the `op.
The code is as follows:
template<typename T, unsigned int N>
T& LU_Matrix<T, N>::operator() (unsigned int i, unsigned int j)
{
return data_[N * i + j];
}
template<typename T, unsigned int N>
std::ostream& operator<< (std::ostream& os, const LU_Matrix<T, N> mat)
{
for (unsigned int i = 0; i < N; ++i)
{
for (unsigned int j = 0; j < N; ++j)
{
os << mat(i, j) << " ";
}
os << std::endl;
}
return os;
}
int main()
{
LU_Matrix<double, 3> lu_mat();
// instantiate lu_mat here
std::cout << lu_mat << std::endl;
return 0;
}
When I run this, it throws the error
no match to call for '(const LU_Matrix<double, 3>) (unsigned int, unsigned int)'
It seems like the compiler should have created the stated function, given the templated function overloading operator<<
. What's going wrong here?