3
void f(int x, int y) { }

struct S {
    void g(int x, int y) { }
};

void (*pf)(int, int) = f;
void (&rf)(int, int) = f;
void (S::*pg)(int, int) = &S::g;
//void (S::&rg)(int, int) = S::g;

I can take a pointer to the free function f(), as well as a reference. But I can only take a pointer to the member function S::g(). Two questions, probably related:

a. Why are references to a member functions not allowed?

b. Why don't member functions decay to pointers the same way free functions do?

Sir Visto
  • 683
  • 1
  • 4
  • 9

0 Answers0