Pergunta

I know the syntax for a non-pointer function type is like void (int). What is the syntax for a non-pointer member function type? i.e. class C; void (C::*)(int), but not a pointer.

Foi útil?

Solução

The answer is void (C::*)(int).

void (C::*)(int) is not a pointer type. Pointers to member functions are not pointers. They are very strange animals.

They just happen to, confusingly, use a name and notation similar to pointers; that's a nuissance we have to live with.

Outras dicas

For any class C and any non-member type T, the pointer-to-member type is T C::*.

So if you have a function of type T = R(A1, A2, A3), then as a member function, it's pointer-to-member type is

T C::* = R (C::*)(A1, A2, A3)

For example, in

struct C
{
    R foo(A1, A2, A3);
    int x;
}

the value &C::foo has this type. Also, &C::x has type int C::*.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top