是否可以使用带有模板化参数的特征块表达式作为左值?
Is it possible to use Eigen block expressions with templated parameters as lvalue?
我在使用特征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
相关文章:
- (C++)分析树以计算返回错误值的简单算术表达式
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 提升精神:解析布尔表达式并简化为规范范式
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 使用正则表达式regex_search在字符串中查找字符串
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- 概念中的cv限定符需要表达式参数列表
- 是否可以使用带有模板化参数的特征块表达式作为左值?
- 如何将特征张量的值作为'if'条件表达式
- 特征:使用特征内禀简化表达式
- 转换特征矩阵类型时,错误:在"float"之前预期主表达式
- 为什么传递特征表达式的临时性会导致访问未定义的内存
- 禁用特征表达式到const引用的临时绑定
- 表达式必须具有常值特征矩阵
- MATLAB find() / Numpy非零特征表达式
- 用特征向量化表达式
- 重用特征表达式模板
- 对于指数,特征表达式模板比手动循环慢