Possible to use varags with member-function pointers?

J

John Silicon

Has anyone ever successfully implimented passing member-functions to a
varargs function? I thought it would be fairly straight-forward, but seems
to come up with nice syntax errors. I've checked my code for syntax errors,
so it must be something with my code effecting the code returned by the
va_arg macro.

I'm implimenting a recursive-decent parser, and I need to make a varargs
function that is passed a variable number of productions owned by the same
class, terminated by a NULL.
The function-pointers are of type "CNode* (CParser::*)(CTokenList*)"
Here's my code:
CNode* do_order(CNode* topLevelNode, CTokenList* toklist) {
va_list args;
va_start(toklist);
while (1) {
production = va_arg(args, CNode* (CParser::*)(CTokenList*));
if (production == NULL) break;
topLevelNode -> pushchild(this->*production(toklist));
}
va_end(args);
return topLevelNode;
}

But, this produces the error:
Parser.cpp(92): syntax error : ')'

Line 92 is the line with va_arg() on it.
 
V

Victor Bazarov

John Silicon said:
Has anyone ever successfully implimented passing member-functions to a
varargs function? I thought it would be fairly straight-forward, but seems
to come up with nice syntax errors. I've checked my code for syntax errors,
so it must be something with my code effecting the code returned by the
va_arg macro.

I'm implimenting a recursive-decent parser, and I need to make a varargs
function that is passed a variable number of productions owned by the same
class, terminated by a NULL.
The function-pointers are of type "CNode* (CParser::*)(CTokenList*)"
Here's my code:
CNode* do_order(CNode* topLevelNode, CTokenList* toklist) {

Don't you need to have ellipsis here

do_order(blah toklist, ...) {
^^^^

???
va_list args;
va_start(toklist);
while (1) {
production = va_arg(args, CNode* (CParser::*)(CTokenList*));
if (production == NULL) break;
topLevelNode -> pushchild(this->*production(toklist));

I think this has to be

topLevelNode->pushchild((this->*production)(toklist));
}
va_end(args);
return topLevelNode;
}

But, this produces the error:
Parser.cpp(92): syntax error : ')'

Line 92 is the line with va_arg() on it.

I am not sure how ellipsis and va_*** macros should behave when
used with pointers to members, but suspect that they won't work.
pointers to members are not built-in types.

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top