What are the implications of over.over#note-2?

83 Views Asked by At

Yeah, just what does over.over#note-2 (which I casually stumbled on while reading this answer) mean? I really don't understand.

For context, I copy the text of over.over#2 below:

If there is no target, all non-template functions named are selected. Otherwise, a non-template function with type F is selected for the function type FT of the target type if F (after possibly applying the function pointer conversion ([conv.fctptr])) is identical to FT.

[Note 2: That is, the class of which the function is a member is ignored when matching a pointer-to-member-function type. — end note]

So, can anybody show me an example where "the class of which the function is a member is ignored when matching a pointer-to-member-function type"?

1

There are 1 best solutions below

0
Passer By On

Note that member functions have regular function types and not some sort of special member function type. For the purpose of [over.over], only the function type matters when selecting an overload and not which class the function belongs to.

In other words

template<int>
struct A
{
    void f() {}
    static void g(A*) {}
    void h(this A&) {}
};

struct B : A<0>, A<1>
{
    using A<0>::f;
    using A<0>::g;
    using A<0>::h;
    using A<1>::f;
    using A<1>::g;
    using A<1>::h;
};

void (A<0>::* pf)() = &B::f;  // ambiguous
void (*pg)(A<0>*) = &B::g;    // not ambiguous
void (*ph)(A<0>&) = &B::h;    // not ambiguous