Jump to content
  • Advertisement
Sign in to follow this  
thedevdan

What does this mean??

This topic is 5039 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!