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 this mean??
I was skimming Enginuity II for some ideas for a garbage collector, when I came across this:
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?
It declares a function type for a function that returns void, takes no parameters AND is a member of the T class.
Function typedefs look always kinda ugly, funcType is the alias in this case.
Function typedefs look always kinda ugly, funcType is the alias in this case.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement