我正在尝试编写一个函数,该函数使用矩阵大小上的模板来获取固定大小的矩阵。我已阅读http://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html但我无法使其完美运行。我无法在函数内的固定大小矩阵上使用固定大小的矩阵块操作。(TutorialBlockOperations.html">http://eigen.tuxfamily.org/dox/group_TutorialBlockOperations.html)
我试图以两种方式做到这一点,但他们都没有工作。
这是函数定义A:
template <int N>
Matrix<double, 3, N> foo(const Matrix<double, 3, N>& v)
{
Matrix<double, 3, N> ret;
Vector3d a = v.leftCols<1>(); // error: expected primary-expression before ')' token
return ret;
}
这是函数定义B:
template<typename Derived>
Eigen::MatrixBase<Derived> bar(const Eigen::MatrixBase<Derived>& v)
{
EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived);
EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime == 3,
THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE);
Eigen::Matrix<double,
Derived::RowsAtCompileTime,
Derived::ColsAtCompileTime> ret;
Vector3d a = v.leftCols<1>(); // error: expected primary-expression before ')' token
return ret;
}
有任何想法吗?