Search code examples
eigen3

Eigen::Map constructuctor complains about "Not a constant expression"


Trying to instanciate a Map, I end up with the following compilation error message :

  error: ‘iCol’ is not a constant expression
    Map< Matrix < scomplex, iCol , iRow  > > m;
src/tstEigen.cpp:161:40: error: ‘iCol’ is not a constant expression
   Map< Matrix < scomplex, iCol , iRow  > > m;
                                            ^
    src/tstEigen.cpp:161:40: note: in template argument for type ‘int’ 
    src/tstEigen.cpp:161:40: error: ‘iRow’ is not a constant expression
    src/tstEigen.cpp:161:40: note: in template argument for type ‘int’ 
    src/tstEigen.cpp:161:40: error: template argument 4 is invalid
    src/tstEigen.cpp:161:40: error: template argument 5 is invalid
    src/tstEigen.cpp:161:40: error: template argument 6 is invalid
    src/tstEigen.cpp:161:42: error: template argument 1 is invalid
       Map< Matrix < scomplex, iCol , iRow  > > m;

Below the snippet :

void tst5( int iCol, int iRow) 
{
  Map< Matrix < scomplex, iCol , iRow  > > m;
}

int main ()
{
  tst5(4,2);
  return 0;
}

May I ask you some hints please ?

Cheers

Sylvain


Solution

  • Sorry for the disturbance, I didn't use the proper sytax, here is the solution :

    void tst5( int iCol, int iRow) 
    {
      scomplex* pData = new scomplex[iCol * iRow];
      Map< Matrix < scomplex, Dynamic, Dynamic  > > m( pData, iCol , iRow);
    }
    

    Cheers