Member function pointer within the class

This is a discussion on Member function pointer within the class within the C++ Programming forums, part of the General Programming Boards category; Is there a way to dereference a member function pointer without using this ? Code: class Obj { private: void ...

  1. #1
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594

    Member function pointer within the class

    Is there a way to dereference a member function pointer without using this?
    Code:
    class Obj
    {
    private:
         void (Obj::*fp[3])(void);  
          ...... 
    };
    
    void Obj::foo()
    {
         if(fp[0] != NULL)
              (this->*fp[0])();
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    To dereference a pointer to member function, you must have an object to call it on. If you don't use this then you'll need to do something else to get the object, such as pass it to foo.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Pointer to a class inside the WindowsProcedure function
    By like_no_other in forum Windows Programming
    Replies: 3
    Last Post: 06-01-2009, 12:52 PM
  3. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  4. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  5. casting a void* to a pointer to a member function
    By Sebastiani in forum C++ Programming
    Replies: 13
    Last Post: 10-15-2002, 08:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21