Returning a pointer to a nonstatic member function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Clay_Culver@yahoo.com

    Returning a pointer to a nonstatic member function?

    I have this code:

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

    NodeGet test()
    {
    return BraidedNode::ge tNextID;
    }

    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::ge tNextID matches the NodeGet typedef

    Anyone have an insights?

  • Clay_Culver@yahoo.com

    #2
    Re: Returning a pointer to a nonstatic member function?

    Sorry, forgot to mention, this is the error message:
    Call.cpp: In function `BraidedNode*(B raidedNode::* test())() const':
    Call.cpp:7: error: invalid use of non-static member function
    `BraidedNode* BraidedNode::ge tNextID() const'
    Call.cpp:7: error: invalid use of non-static member function

    Comment

    • Peter Steiner

      #3
      Re: Returning a pointer to a nonstatic member function?

      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::g etNextID;
      }

      Comment

      • Clay_Culver@yahoo.com

        #4
        Re: Returning a pointer to a nonstatic member function?

        That fixed it, thank you.

        Comment

        Working...