I'm getting compiler errors when attempting to access a template member function of a template class from within another template class. A function call to getSubmatrix
results in the compiler warnings, "expression result unused", about the parameters (0, 0)
, finally failing with the compiler error "reference to non-static member function must be called".
The matrix class:
template <std::size_t m, std::size_t n, typename T, std::size_t rowPadding = 0>
class Matrix
{
public:
...
template <std::size_t p, std::size_t q>
Matrix<p, q, T, n - q>& getSubmatrix(std::size_t column, std::size_t row)
{
...
}
};
The transform class:
template <typename T>
class Transform
{
public:
...
Matrix<4, 4, T> matrix() const
{
...
Matrix<4, 4, T> result;
result.getSubmatrix<3, 3>(0, 0) = Matrix<3, 3, T>();
...
}
};
Note that changing the matrix type to Matrix<4, 4, float>
rather than Matrix<4, 4, T>
will result in valid compilation. The compiler is clang 4.0 and the language version is C++11.
You should add keyword template
:
result.template getSubmatrix<3, 3>(0, 0) = Matrix<3, 3, T>();
// ^^^^^^^^
Without it, compiler will think that <
is a comparison operator.
PS. In that case, g++ produces a little more understandable error:
error: invalid operands of types
<unresolved overloaded function type>
andint
to binaryoperator<
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With