小编Tho*_*ger的帖子

在Eigen中复制模板化函数参数

我正在编写一个利用Eigen数据类型的通用类。我已经遇到了将构造函数参数分配给类成员变量的问题。我的代码的简化版本是:

template <typename Derived>
class A
{
public:
  Eigen::Matrix<Derived> M; // error C2976: too few template parameters

A(const Eigen::DenseBase<Derived> & V)
{
  M = V.eval(); // I would want to snapshot the value of V.
}
};
Run Code Online (Sandbox Code Playgroud)

我的问题是,现在M应该是哪种数据类型?我尝试了多种选择,例如:

Eigen::internal::plain_matrix_type_column_major<Derived> M;
Eigen::DenseBase<Derived> M;
Run Code Online (Sandbox Code Playgroud)

但是它们只会产生不同的错误。请注意,我使用C ++ 17并期望从构造函数中推断类模板参数。

c++ class-template eigen template-argument-deduction c++17

6
推荐指数
2
解决办法
620
查看次数