我正在为一个函数创建一个 typedef,该函数将用于调用存储在字符串中的任意函数到函数指针映射。我确信问题与如何通过我的代码中的许多对象声明和引用类型有关,但这是我能想到如何做我需要做的唯一方法
这是 fmap.h 这里我声明了 fmap 类和 executefunctions 类,函数指针的 typedef 是 fmap 的公共成员的第一行
class Web;
class Matlab;
class Word;
class Node;
class ExecFunctions
{
public:
ExecFunctions(){}
/**
Function: travel
*/
int travel(Web *concepts, Matlab *mat, Word * words, int reqIdx, string theWord, vector<string> *dependsMet);
};
class FMap
{
public:
typedef int (ExecFunctions::*ExecFunc)(Web *, Matlab *, Word *, int, string, vector<string> *);
ExecFunc getFunc(string funcName){
return theFuncMap.descrToFuncMap[funcName];
}
private:
class FuncMap {
public:
FuncMap() {
descrToFuncMap["travel"] = &ExecFunctions::travel;
}
std::map<std::string, ExecFunc> descrToFuncMap;
};
};
#endif
接下来是 web.h 我只包括我认为相关的部分
#include "fmap.h"
class Node
{
private:
....
//pointer to execcution function
FMap::ExecFunc func;
//fmap function used to access execution function pointers
FMap *functionMap;
.....
public:
FMap::ExecFunc getExecFunc();
};
现在我认为是 web.cpp 的相关部分
Node::Node(string name, Node *nodeParent)
{
attrList = new Attr();
nodeName = name;
........
func = functionMap->getFunc(name);
}
现在终于。这是我得到错误的地方。错误行之前有三行注释,解释了我遇到的错误。
void process(Util myUtil, Web *concepts, Matlab *mat, string path)
{
int funcP
bool dependsProcessed = false;
vector<string> *dependsDone = new vector<string>();
FMap::ExecFunc funcToCall;
funcToCall = realMeanings[i][j]->getConcept()->getExecFunc();
//the line bellow this comment is where I'm getting the error. Visual Studio says
//that funcToCall must have (pointer-to) function type, and then the VS compiler says
//diabot.cpp(177): error C2064: term does not evaluate to a function taking 6 arguments
funcPtrRet = funcToCall(concepts, mat, realMeanings[i][j], reqConceptsIdx[i][j], queryWords[i], dependsDone);
return;
}
任何人都可以提供的任何帮助将不胜感激。
谢谢大家