[cfe-dev] (Unexpected) Method type

Abramo Bagnara abramobagnara at tin.it
Mon Jan 11 11:38:11 CST 2010


Il 11/01/2010 16:51, Douglas Gregor ha scritto:
> 
> Template argument deduction is another place where we see that the type of a member function is just a normal function type, since a pointer to member function is really just a pointer to member where the member has function type:
> 
>   template<typename T> struct X;
>   template<typename T, typename Class> struct X<T Class::*> { };
> 
>   struct Y { };
> 
>   X<int (Y::*)(int)> x; // instantiates partial specialization with Class=Y, T=int(int).

Now I got it: from the code above it's clear that a method (static or
not) is simply a class member with function type.

I've never interpreted non static method nature in this way: I was
interpreting them as a distinct kind of functions with implicit argument
and I interpreted the & operator applied to member as an ordinary
address-of operator whose type is always T* if member has type T.

Instead it seems that the & operator applied to member does not respect
this assumption.

Now I wonder if it's correct to build the AST UnaryOperator with the
same kind of operator for both non-static members and for other things,
but I believe this is a minor point.

Many thanks to all of you for your explanations.


More information about the cfe-dev mailing list