Possible to use varags with member-function pointers?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Silicon

    Possible to use varags with member-function pointers?

    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::*)(CT okenList*)"
    Here's my code:
    CNode* do_order(CNode* topLevelNode, CTokenList* toklist) {
    va_list args;
    va_start(toklis t);
    while (1) {
    production = va_arg(args, CNode* (CParser::*)(CT okenList*));
    if (production == NULL) break;
    topLevelNode -> pushchild(this->*production(to klist));
    }
    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.



  • Victor Bazarov

    #2
    Re: Possible to use varags with member-function pointers?

    "John Silicon" <jsilicon@earth link.net> wrote...[color=blue]
    > Has anyone ever successfully implimented passing member-functions to a
    > varargs function? I thought it would be fairly straight-forward, but[/color]
    seems[color=blue]
    > to come up with nice syntax errors. I've checked my code for syntax[/color]
    errors,[color=blue]
    > 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::*)(CT okenList*)"
    > Here's my code:
    > CNode* do_order(CNode* topLevelNode, CTokenList* toklist) {[/color]

    Don't you need to have ellipsis here

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

    ???
    [color=blue]
    > va_list args;
    > va_start(toklis t);
    > while (1) {
    > production = va_arg(args, CNode* (CParser::*)(CT okenList*));
    > if (production == NULL) break;
    > topLevelNode -> pushchild(this->*production(to klist));[/color]

    I think this has to be

    topLevelNode->pushchild((thi s->*production)(t oklist));
    [color=blue]
    > }
    > 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.[/color]

    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


    Comment

    Working...