function pointer call syntax
Posted on 2003-12-04
I have a class Parser and I want to call function pointers in the global namespace from with an argument of Parser.
The unworking code I have now is:
typedef void (*handler) (*this );
and from handler.h I have defined:
void * doVariable_second (Parser *);
void * doInclude_second (Parser *);
void * doIf (Parser *);
void * dodoIf_second (Parser *);
In file included from Parser.cpp:10:
Parser.h:29: invalid use of `this' at top level
Parser.h:29: typedef declaration includes an initializer
Parser.h:29: typedef `handler' is initialized
Parser.cpp: In member function `virtual void Parser::set_handlers()':
Parser.cpp:56: invalid conversion from `void*(*)(Parser*)' to `void*'
Parser.cpp:56: initializing argument 2 of `void
std::allocator<char> >, void*)'
Parser.cpp:57: invalid conversion from `void*(*)(Parser*)' to `void*'
I have one question:
how can I pass a class object as an instance to a member function using this pointer?
and another (i guess):
should I separate the function pointers into another class, contain the class in class parser, or leaeve them global?
note that using function pointers I was able to call
if (debug > 0) cerr << "Parser::set_handlers() " << endl;
addFirstHandler ("if", doIf);
and so on for other function handlers.
void addFirstHandler (string , handler );
the above populated
map < string, handler > first_handler_map;
which I could then search for string match and call the function. But, how about passing in a Parser object.