Hi! I need to make a function which adds a function pointer to map. It would be something like this:
bool RegisterFunction (string name, FunctionPointer function).
But I have problem with calling it, because I don't know how to pass function to it instead of result of function (when I call this as here:
RegisterFunction ("run", Run())
it doesn't works, neither works Run without parentheses, nor:
- *Run()
- &Run()
- *Run
- &Run
How to fix this?
Edit:
The error is:
parser.cpp|9|error: no matching function for call to
'MCXJS::Parser::RegisterFunction(const char [4], <unresolved overloaded function type>)'|
The RegisterFunction() and Run() functions are in Parser class, which is in MCXJS namespace.
Class body is:
class Parser
{
public:
Parser ();
CVariable RegisterFunction (FunctionPointer);
bool RegisterErrorHandler (ErrorType, ErrorHandlerPointer);
CVariable Run (std::string);
bool AlwaysDefaultErrorHandler;
int MaxCallStackSize;
private:
std::map <std::string, FunctionPointer> ExternalFunctions;
std::map <ErrorType, ErrorHandlerPointer> ErrorHandlers;
ErrorHandlerPointer DefaultErrorHandler;
};
And the parser.cpp file:
Parser::Parser ():
AlwaysDefaultErrorHandler (true), MaxCallStackSize (4)
{
RegisterFunction ("run", Run);
};
CVariable Parser::Run (std::string path)
{
return 5;
};
Typedefs:
typedef CVariable (*FunctionPointer) (std::string);
typedef void (*ErrorHandlerPointer) (ErrorData);