Sign in to follow this  
thedevdan

What does this mean??

Recommended Posts

I was skimming Enginuity II for some ideas for a garbage collector, when I came across this:
class Functor : public IMMObject
{
public:
   virtual void operator ()()=0;
};

template<class T>
class ObjFunctor : public Functor
{
   protected:
      T *obj;
      typedef void (T::*funcType)(); //What the heck does this line do??
      funcType func;
   public:
      AUTO_SIZE;
   
      ObjFunctor(T *o, funcType f) 
      { obj=o; func=f; }
   
      void operator ()() 
      { (obj->*func)(); }
};


What does the commented line do? It seems that it is missing the name of the alias. Typedefs go 'typedef type alias', but I don't see the alias there. Could someone please explain?

Share this post


Link to post
Share on other sites
I'm gonna get beaten, I know it. In fact, I've already been beaten.

Yes, it defines the type of a pointer to a function. The syntax is bizarre, but not completely out there. void (T::* )() is the type, and funcType is its name, so ignoring the necessary trailing parentheses it is the usual typedef type name.

It's all to do with the operator precedence of *, that's why you have to wrap the name in parentheses.

Share this post


Link to post
Share on other sites
to be more specific its a pointer to member function which is not exactly the same as a pointer to function because you can't do much with a pointer to member function on its own, you need an instance of the type the member function belongs to.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this