自动更改指向函数的指针的名称

Change name of a Pointer to function automatically

本文关键字:指针 函数      更新时间:2023-10-16

我想自动更改指向函数的指针的名称,在本例中,指向函数的指针的名称为"CImageGraph",如下所示。例如,我希望指针名称为"pGraph"加上循环索引"ttt";然而,我得到错误。那么,自动更改指针名称的最佳方法是什么呢?谢谢。

const word nStates      = 9; 
const int T             = 6; 
const int nState        = 2; 
for(int ccc = 0; ccc < nStates; ccc++){
    for(int ttt = 0; ttt < T; ttt++){
        string pGraph = "pGraph"+ttt;
        CImageGraph *pGraph = new CImageGraph(nState);
    }
}

所以我设法找到一个解决方案使用数组,感谢提示。解决方案如下:

const word nStates      = 9; 
const int T             = 6; 
const int nState        = 2; 
for(int ccc = 0; ccc < nStates; ccc++){
CImageGraph **pGraph = new CImageGraph*[T];
    for(int ttt = 0; ttt < T; ttt++){
        pGraph[ttt] =  new CImageGraph(nState);
        //Other processes
    }
}