Returning a pointer to a nonstatic member function?

Discussion in 'C++' started by Clay_Culver@yahoo.com, Nov 4, 2005.

  1. Guest

    I have this code:

    typedef BraidedNode* (BraidedNode::*NodeGet)() const;

    NodeGet test()
    {
    return BraidedNode::getNextID;
    }

    This code compiles under MSVC 7.1, but g++ (GCC 3.4.4) will not compile
    it. Maybe I'm missing a subtle portion of the standard.... I know
    that the above is at least partially correct (MSVC compiles it). Does
    anyone know what I need to do to get this to compile?

    info:
    BraidedNode is a class
    getNextID is a non-static member function of BraidedNode
    BraidedNode::getNextID matches the NodeGet typedef

    Anyone have an insights?
    , Nov 4, 2005
    #1
    1. Advertising

  2. Guest

    Sorry, forgot to mention, this is the error message:
    Call.cpp: In function `BraidedNode*(BraidedNode::* test())() const':
    Call.cpp:7: error: invalid use of non-static member function
    `BraidedNode* BraidedNode::getNextID() const'
    Call.cpp:7: error: invalid use of non-static member function
    , Nov 4, 2005
    #2
    1. Advertising

  3. to get a pointer to a member function you have to prepend the function
    with the address-of (&) operator. only global functions are implicitely
    converted to pointers.

    try:

    NodeGet test()
    {
    return &BraidedNode::getNextID;
    }
    Peter Steiner, Nov 4, 2005
    #3
  4. Guest

    That fixed it, thank you.
    , Nov 4, 2005
    #4
    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. Fraser Ross
    Replies:
    4
    Views:
    1,025
    Fraser Ross
    Aug 14, 2004
  2. The|Godfather
    Replies:
    7
    Views:
    3,922
    Miles Bader
    Oct 24, 2006
  3. fl
    Replies:
    12
    Views:
    807
    Salt_Peter
    Dec 31, 2007
  4. Jeffrey
    Replies:
    7
    Views:
    405
    James Kanze
    Sep 30, 2008
  5. Computerjunkie
    Replies:
    0
    Views:
    934
    Computerjunkie
    Apr 6, 2012
Loading...

Share This Page