Eigen::Map 构造函数抱怨 "Not a constant expression"

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

尝试实例化地图时,我得到以下编译错误消息:

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

我可以问你一些提示吗?

干杯

西尔万

抱歉打扰了,我没有使用正确的语法,这里是解决方案:

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

干杯