Eigen :: Map构造函数抱怨“不是常量表达式”

时间:2019-07-08 14:05:18

标签: eigen3

试图实例化地图,最终出现以下编译错误消息:

  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;

摘要下方:

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

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

请问一些提示吗?

欢呼

西尔万

1 个答案:

答案 0 :(得分:0)

对不起,我没有使用正确的语法,这是解决方法:

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

欢呼