Thread: Pointer to a Member Function

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209
    Quote Originally Posted by Magos
    ex:
    Code:
    class CStuff
    {
      public:
        void Method(int Arg);
    };
    
    typedef void(CStuff::*Pointer)(int);
    Lemme complete this for you (this is how you would use it):

    Code:
    CStuff stuff;
    
    Pointer myFuncPtr = CStuff::Method;
    
    stuff.myFuncPtr(5);

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Quote Originally Posted by homeyg
    Originally Posted by Magos
    Code:
    class CStuff
    {
      public:
        void Method(int Arg);
    };
    
    typedef void(CStuff::*Pointer)(int);
    Lemme complete this for you (this is how you would use it):

    Code:
    CStuff stuff;
    
    Pointer myFuncPtr = CStuff::Method;
    
    stuff.myFuncPtr(5);
    A couple of problems:

    1) There is no function definition anywhere.

    2) VC++6 gives me an error using this syntax:

    stuff.myFuncPtr(5);

    It complains that myFuncPtr is not a member of CStuff. Does that work for you? What compiler are you using?

  3. #3
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209
    Quote Originally Posted by 7stud
    A couple of problems:

    1) There is no function definition anywhere.

    2) VC++6 gives me an error using this syntax:

    stuff.myFuncPtr(5);

    It complains that myFuncPtr is not a member of CStuff. Does that work for you? What compiler are you using?
    Okay.
    Last edited by homeyg; 04-01-2006 at 08:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM