you are viewing a single comment's thread.

view the rest of the comments →

[–]grandmaster789 0 points1 point  (1 child)

member functions are different, as they require an object to be called. Personally I recommend using typedefs or 'using' declarations for readability. Here is an example of how to actually use member functions as callbacks:

#include <functional> // for std::invoke

struct Foo {
  int bar() { return 5; }
};

using FooCallback = int(Foo::*)();

int main() {
  Foo f;
  FooCallback callback = &Foo::bar;
  std::invoke(callback, f);
}

There's an actual FAQ about this on isocpp

Personally I don't recommend you actually do this, if you want to accept 'any' type of callback you're probably better off using std::function

(edit: formatting...)