Skip to main content
gamedev.net
🔒 Locked

member function pointers another way ?

Started by DMINATOR Dec 9, 2005 at 1:05 PM 0 replies 650+ views
Original Post
DMINATOR
DMINATOR
Hi I was playing around with class member functions. Here is one sample straigh from the head just to show the idea. This is the way I have seen everyone is using member function pointers:

class MyClass
{
   //possible code samples
   void Sample1();
   void Sample2();
 
   //pointer typedef
   typedef void (MyClass::*Big)();
   
   //pointer to be used
   Big big;

   void Select(int ver)
   {
      //assign specific function
      if( ver == 0)
      {
        big = &MyClass::Sample1();
      }
      else
          {
             big = &MyClass::Sample2();
          }

      //and call our pointer
      (this->*big)();
   }
};

My question is. Why should the typedef be used ? Why not just assign Big the function and use it later on ? Thanks for the help.
d_emmanuel
d_emmanuel
The purpose of the typedef is to create an alias for a pointer to a void member function that takes no arguments. It's used for readability and cuts down on the amount of typeing you have to do. Also, you can't assign to Big since it's a type. You can only assign to an instance of type Big.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.