2013-07-09 56 views
2

所以我试图做一个类,基本上充当与特征矩阵分区的接口,以及一些额外的功能。我的数据结构的一个基本副本是:在编译时的特征断言错误,不清楚的错误

template <class T> 
class DataFile { 
public: 
    typedef Eigen::Matrix<DataType, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> RMatrix; 
    DataFile(int inputRows, int inputColumns) { 
     dataMatrix = RMatrix::Zero(inputRows, inputColumns); 
    } 
    inline typename RMatrix::RowXpr getSample(const int row) { return dataMatrix.row(row) } 

private: 
    RMatrix dataMatrix; 

这只是一个简单的看看我做了什么以及哪些似乎是相关的。当我使用Qtcreator和MSVC2008编译我的代码,我得到了以下错误消息:

c:\apis_x64\eigen-eigen-ca142d0540d3\eigen\src/Core/DenseCoeffsBase.h(390) : error C2039: 'THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD' : is not a member of 'Eigen::internal::static_assertion<condition>' 
     with 
     [ 
      condition=false 
     ] 
     c:\apis_x64\eigen-eigen-ca142d0540d3\eigen\src/Core/DenseCoeffsBase.h(388) : while compiling class template member function 'float &Eigen::DenseCoeffsBase<Derived,Level>::operator [](__int64)' 
     with 
     [ 
      Derived=Eigen::Matrix<float,-1,-1,1>, 
      Level=1 
     ] 
     c:\apis_x64\eigen-eigen-ca142d0540d3\eigen\src/Core/DenseCoeffsBase.h(653) : see reference to class template instantiation 'Eigen::DenseCoeffsBase<Derived,Level>' being compiled 
     with 
     [ 
      Derived=Eigen::Matrix<float,-1,-1,1>, 
      Level=1 
     ] 
     c:\apis_x64\eigen-eigen-ca142d0540d3\eigen\src/Core/util/XprHelper.h(365) : see reference to class template instantiation 'Eigen::DenseCoeffsBase<Derived>' being compiled 
     with 
     [ 
      Derived=Eigen::Matrix<float,-1,-1,1> 
     ] 
     c:\apis_x64\eigen-eigen-ca142d0540d3\eigen\src/Core/DenseBase.h(53) : see reference to class template instantiation 'Eigen::internal::special_scalar_op_base<Derived,Scalar,OtherScalar>' being compiled 
     with 
     [ 
      Derived=Eigen::Matrix<float,-1,-1,1>, 
      Scalar=float, 
      OtherScalar=float 
     ] 
     c:\apis_x64\eigen-eigen-ca142d0540d3\eigen\src/Core/MatrixBase.h(65) : see reference to class template instantiation 'Eigen::DenseBase<Derived>' being compiled 
     with 
     [ 
      Derived=Eigen::Matrix<float,-1,-1,1> 
     ] 
     c:\apis_x64\eigen-eigen-ca142d0540d3\eigen\src/Core/PlainObjectBase.h(89) : see reference to class template instantiation 'Eigen::MatrixBase<Derived>' being compiled 
     with 
     [ 
      Derived=Eigen::Matrix<float,-1,-1,1> 
     ] 
     c:\apis_x64\eigen-eigen-ca142d0540d3\eigen\src/Core/Matrix.h(144) : see reference to class template instantiation 'Eigen::PlainObjectBase<Derived>' being compiled 
     with 
     [ 
      Derived=Eigen::Matrix<float,-1,-1,1> 
     ] 
     d:\users\public\documents\myCode\DataFilesV2.h(46) : see reference to class template instantiation 'Eigen::Matrix<_Scalar,_Rows,_Cols,_Options>' being compiled 
     with 
     [ 
      _Scalar=float, 
      _Rows=-1, 
      _Cols=-1, 
      _Options=1 
     ] 
c:\apis_x64\eigen-eigen-ca142d0540d3\eigen\src/Core/DenseCoeffsBase.h(390) : error C2065: 'THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD' : undeclared identifier 

线d:\users\public\documents\myCode\DataFilesV2.h(46) reffers在我的代码行inline typename RMatrix::RowXpr getSample(const int row) { return dataMatrix.row(row) }。我之前已经能够在我的代码的其他部分获得这项工作,所以我的想法是这是一个叫它的东西。然而,在我称之为的这段时间里,没有[]的使用或不正确的使用RowXpr.我有很多代码需要通过,所以我不确定如何找到这个错误并且可以使用关于可能出错的一些想法或者我可以如何寻找导致错误的原因。

+1

您是否看到错误消息的“THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD”部分?另外我会看看'XprHelper.h'的第365行。 –

+0

是的,我看过那部分。这就是为什么我通过我的代码搜索寻找[]运算符的用法应用于我的函数构造的任何向量。 – mculp

回答

1

我最终发现了这个错误,这是Eigen所说的那个错误。我有一个从数组转换为Eigen矩阵的剩余[]。但是这个问题甚至与错误指向的地方都没有关系。我必须通过并且注释错误指向的位置,直到最终错误消失,并且我可以推断哪部分代码是错误的真正源。

+0

谢谢,有同样的问题,错误被指示在错误的位置。在我的情况下,我已经将一个变量的类型从VectorXd更改为MatrixXd,但稍后在此代码中使用了x()成员,该成员可在内部合理使用[] -Operator。 – Janosch

1

一旦我固定缺少分号的getSample定义,既克++ - 4.8和铛++ - 3.3编译下方(基本你用一琐碎DataType结构例)的简单的测试案例:

$ cat test.cpp 
#include <Eigen/Dense> 

struct DataType 
{ 
    double x; 
}; 

template <class T> 
class DataFile { 
public: 
    typedef Eigen::Matrix<DataType, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> RMatrix; 
    DataFile(int inputRows, int inputColumns) { 
     dataMatrix = RMatrix::Zero(inputRows, inputColumns); 
    } 
    inline typename RMatrix::RowXpr getSample(const int row) { return dataMatrix.row(row); } 

private: 
    RMatrix dataMatrix; 
}; 

int main() 
{ 
    return 0; 
} 

编译为罚款:

$ clang++-mp-3.3 -I/opt/local/include/eigen3 test.cpp 
$ g++ -I/opt/local/include/eigen3 test.cpp 

所以,除了分号,你的例子对我来说显得很好。我的例子是为你编译的吗?

+0

是的,我可以让你的代码工作。我已经在另一个课程中完成了这个任务,并且在那里我没有任何错误。 – mculp