Possible to use varags with member-function pointers?

Discussion in 'C++' started by John Silicon, Jul 29, 2003.

  1. John Silicon

    John Silicon Guest

    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.
     
    John Silicon, Jul 29, 2003
    #1
    1. Advertising

  2. "John Silicon" <> wrote...
    > 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
     
    Victor Bazarov, Jul 29, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. n2xssvv g02gfr12930

    Smart pointers and member function pointers

    n2xssvv g02gfr12930, Nov 26, 2005, in forum: C++
    Replies:
    3
    Views:
    501
    n2xssvv g02gfr12930
    Nov 27, 2005
  2. Replies:
    18
    Views:
    542
    Diego Martins
    Feb 26, 2007
  3. Hamish
    Replies:
    3
    Views:
    607
    Alf P. Steinbach
    Jan 25, 2008
  4. paul
    Replies:
    8
    Views:
    744
    Alf P. Steinbach
    Apr 30, 2009
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    737
Loading...

Share This Page