使用特征定义动态矩阵
Define a dynamic matrix with EIGEN
我对这段代码有问题,主要思想是使用模板中定义的列数创建一个typedef'Base':
// --- Row dynamic matrix
template< class T, int cols >
class RowDynamicMatrixRowMajor : public Eigen::Matrix< T, Eigen::Dynamic, cols,
Eigen::RowMajor | Eigen::AutoAlign >{
public:
typedef Eigen::Matrix< T, Eigen::Dynamic, cols, Eigen::RowMajor | Eigen::AutoAlign > Base;
RowDynamicMatrixRowMajor( void ) : Base()
{}
template< typename OtherDerived >
RowDynamicMatrixRowMajor( const Eigen::MatrixBase< OtherDerived > & other )
: Base( other )
{}
template< typename OtherDerived >
RowDynamicMatrixRowMajor & operator= ( const Eigen::MatrixBase< OtherDerived > & other )
{
this->Base::operator=( other );
return *this;
}
};
但是,在Visual Studio 2012中编译代码时,我收到此错误:
错误1 错误 C2975:"_Cols":"特征::矩阵"的模板参数无效;预期的编译时常量表达式 z:\desktop\光一致性-视觉里程计-主\phovo\include\Matrix.h 97 1 光一致性视觉测程法
对于该文件,有 20 个类似的错误,但我无法识别错误。
我可以毫无问题地编译和运行它(g ++ 4.9),所以这不是错误的根源。虽然这不是答案,但我发布了,因为我无法在评论中发布代码。
template< class T, int cols >
class RowDynamicMatrixRowMajor : public Eigen::Matrix< T, Eigen::Dynamic, cols,
Eigen::RowMajor | Eigen::AutoAlign >
{
public:
typedef Eigen::Matrix< T, Eigen::Dynamic, cols, Eigen::RowMajor | Eigen::AutoAlign > Base;
RowDynamicMatrixRowMajor( void ) : Base()
{}
template< typename OtherDerived >
RowDynamicMatrixRowMajor( const Eigen::MatrixBase< OtherDerived > & other )
: Base( other )
{}
template< typename OtherDerived >
RowDynamicMatrixRowMajor & operator= ( const Eigen::MatrixBase< OtherDerived > & other )
{
this->Base::operator=( other );
return *this;
}
};
int main()
{
RowDynamicMatrixRowMajor<double, 10> a;
}
作为旁注,你确定要从本征派生吗?http://eigen.tuxfamily.org/dox/TopicCustomizingEigen.html
我发现键入我需要的东西要简单得多(您需要对模板别名的 C++11 支持),例如在您的情况下:
template<typename Scalar, int cols> // Eigen::MatrixX<type> (where type = Scalar)
using RowDynamicMatrixRowMajor =
Eigen::Matrix<Scalar, Eigen::Dynamic, cols, Eigen::RowMajor | Eigen::AutoAlign>;
然后使用它,例如
RowDynamicMatrixRowMajor<double, 10> a;
相关文章:
- g++用户定义的动态链接库上的全局new和delete运算符
- 当我使用自定义类型创建动态数组时,即使使用字符串,它似乎也不起作用
- 具有自定义构造函数 (C++) 的类型的动态数组分配
- 删除动态数组时未定义标识符
- 虚拟成员函数的定义是否强制在同一转换单元中动态初始化静态数据成员?
- 动态填充的组合框不显示文本,列表未定义
- C++17 和更新的 std::分配器是否适用于动态数量的自定义堆?
- 带有log4cxx的自定义和动态附加程序的配置
- 我可以从样式表 (qss) 更改自定义动态属性吗?
- 动态分配自定义类的数组和重载运算符
- 复制构造函数C++中自定义类的动态数组
- 如何在没有动态内存分配(堆)的情况下为可变大小数组(矢量)定义安全容器或视图
- 使用自定义工具集获取动态退出析构函数链接错误 - eh 矢量析构函数
- 为什么要对堆栈中的内存使用自定义动态内存分配?
- 如何在C++中动态定义成员函数
- 动态定义函数返回类型
- 将指针传递给在 C++ 中动态定义的内置类型
- C++动态定义函数
- 在c++中动态定义函数
- 在类构造函数中动态定义Stack,它是私有成员