是否可以使用带有模板化参数的特征块表达式作为左值?

Is it possible to use Eigen block expressions with templated parameters as lvalue?

本文关键字:表达式 特征 参数 可以使 是否      更新时间:2023-10-16

我在使用特征C++库的函数时遇到问题。这是他们示例之一的模板化版本,但我似乎无法使其在 xcode 中工作。

template <typename Scalar>
void foo(){
Eigen::Matrix<Scalar, 2, 2> m = Eigen::Matrix<Scalar, 2, 2>::Identity();
Eigen::Matrix<Scalar, 4, 4> a = Eigen::Matrix<Scalar, 4, 4>::Constant(0.6);
a.topLeftCorner<2,2>() = m; //Expected expression!
std::cout << "result:" << std::endl << a << std::endl << std::endl;
}

由于"预期表达式"错误,此代码无法编译。我实际上并没有在任何地方调用该函数,如果我不模板化它并使用 double 或 float 代替,它可以正常工作。有什么理由它不应该适用于模板化版本吗?

你需要写

a.template topLeftCorner<2,2>() = m;

这里对此进行了解释:http://eigen.tuxfamily.org/dox-devel/TopicTemplateKeyword.html