0
votes

I have a templated matrix library called CMatrix which interfaces with Eigen library for some functions. In order to switch between libraries I have a simple function:

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;
}

Here the typename T is atomic types such as double, float...

I call this function in another function as:

 MatrixXd eigMat=m.ToMatrixXd();

I get the following error message:

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]

It seems that number of rows and columns stay as negative which does not make sense. I tried:

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

I still get the above-mentioned error message. What could be going on wrong?

1
` MatrixXd eigMat=m.ToMatrixXd();` where do you make m?xaxxon
Why your code works even after returning a local variable? "MatrixXd matrixXd''. Can somebody explain why this code is correct.Rohan Ghige
It is not a locally created pointer, just a local variablemacroland

1 Answers

0
votes

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

It seems that the m in MatrixXd eigMat=m.ToMatrixXd(); is const but template <typename T> MatrixXd CMatrix<T>::ToMatrixXd() is not a const method.