我正在爲函數創建一個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();
};
現在我認爲是t他相信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;
}
任何人都可以給任何幫助將不勝感激。
謝謝大家提前
這就是很多代碼,其中大部分代碼可能與問題無關。你可以嘗試簡化你的例子嗎? – 2011-04-28 07:26:13
對不起,我無法將代碼分解爲基本問題。我把它削減了一下。讓我知道如果它仍然很多 – jeffminton 2011-04-28 07:35:27