2016-05-15 34 views
0

我有一个名为CMatrix的模板化矩阵库,它与Eigen库连接以获得某些功能。为了库之间进行切换我有一个简单函数:Eigen MatrixXd作为返回类型

template <typename T> 
MatrixXd CMatrix<T>::ToMatrixXd() 
{ 
    const int nrow=m_row; 
    const int ncol=m_column; 
    MatrixXd matrixXd(nrow,ncol); 
    for(unsigned int i=0;i<nrow;i++) 
     for(unsigned int j=0;j<ncol;j++) 
      matrixXd(i,j)=GetCellValue(i,j); 

    return matrixXd; 
} 

在这里,类型名T是原子的类型,如双,浮子...

我调用该函数在另一个函数为:

MatrixXd eigMat=m.ToMatrixXd(); 

我收到以下错误信息:

const math::CMatrix <double> as 'this' argument of 'Eigen::MatrixXd math::CMatrix<T>::ToMatrixXd() [with T = double; Eigen::MatrixXd = Eigen::Matrix <double, -1, -1>] discards qualifiers [-fpermissive]

看来,行数和列数保持为负值,这是没有意义的。我试过了:

MatrixXd eigMat(nrow,ncolumn) //both nrow and ncolumn positive 
eigMat=m.ToMatrixXd(); 

我还是得到了上面提到的错误信息。有什么可能会发生错误?

+0

'MatrixXd eigMat = m.ToMatrixXd();'你在哪里做'm'? – xaxxon

回答

0

**const** math::CMatrix <double> as 'this' argument

看来,在MatrixXd eigMat=m.ToMatrixXd();mconsttemplate <typename T> MatrixXd CMatrix<T>::ToMatrixXd()不是const方法。

+0

谢谢,的确非常漂亮!我总是把'const'标识符,但在这种情况下完全忘记了,并在错误消息中以不同方向导致行和列为负。 – macroland