Cannot call a member function of a template of a template class from another template class

I get compiler errors when trying to access the template member function of a template class from another template class. The call to the getSubmatrix function leads to compiler warnings, β€œthe result of the expression is not used,” about the parameters (0, 0) , and finally, in the case of a compiler error, β€œa reference to a non-stationary member function must be called”.

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) { ... } }; 

Conversion 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>(); ... } }; 

Please note that changing the matrix type to Matrix<4, 4, float> , and not Matrix<4, 4, T> will lead to proper compilation. The clang 4.0 compiler, and the language version is C ++ 11.

+6
source share
1 answer

You must add the template keyword:

 result.template getSubmatrix<3, 3>(0, 0) = Matrix<3, 3, T>(); // ^^^^^^^^ 

Without this, the compiler will assume that < is a comparison operator.

PS. In this case, g ++ creates a slightly more understandable error:

error: invalid operands of types <unresolved overloaded function type> and int to binary operator<

+12
source

Source: https://habr.com/ru/post/944260/


All Articles