Reputation: 10045
I'm trying to write a function that takes an Eigen::Matrix from either type double or float. This function works fine for floats:
Eigen::Matrix<float, 4, 4> foo(const Eigen::Matrix<float, 4, 4> &T)
{
Eigen::Matrix<float, 4, 4> result;
result.block<3,3>(0,0) = T.block<3,3>(0,0).transpose();
return result;
}
However, as soon as I make the "float" a template:
template <typename Scalar>
inline Eigen::Matrix<Scalar, 4, 4> foo(const Eigen::Matrix<Scalar, 4, 4> &T)
{
Eigen::Matrix<Scalar, 4, 4> result;
result.block<3,3>(0,0) = T.block<3,3>(0,0).transpose();
return result;
}
I get this error with gcc 4.9.1 on linux:
.../utils.hpp: In function 'Eigen::Matrix core::math::foo(const Eigen::Matrix&)': .../utils.hpp:77:47: error: request for member 'transpose' in '(0, 0)', which is of non-class type 'int' result.block<3,3>(0,0) = T.block<3,3>(0,0).transpose();
What could be the problem here?
Upvotes: 0
Views: 90
Reputation: 217275
Once the function is template some calls are dependent of template and so you have to add some template
keyword, try:
template <typename Scalar>
inline Eigen::Matrix<Scalar, 4, 4> foo(const Eigen::Matrix<Scalar, 4, 4> &T)
{
Eigen::Matrix<Scalar, 4, 4> result;
result.template block<3,3>(0,0) = T.template block<3,3>(0,0).transpose();
return result;
}
Upvotes: 3