1

I'm simply trying to convert my current typedef:

typedef void (Foo::*CallbackName)(int arg);

Into a function alias, which I have looking like:

template <class T>
using T_CallbackName = void(T::*CallbackName)(int arg); 

Is this correct? Alias declarations seem straightforward, but function typedefs have weird syntax, and it's not clear to me how to template them.

Danny
  • 354
  • 3
  • 13

2 Answers2

2

Simply:

template <class C>
using T_CallbackName = void (C::*)(int);

You can let arg if you want, but CallbackName should be removed.

Btw, your first typedef can be written:

using CallbackName = void (Foo::*)(int);
Jarod42
  • 203,559
  • 14
  • 181
  • 302
0

you can also use auto to define funtion pointer:

const auto T_CallbackName = Foo::CallbackName

or function reference

auto& T_CallbackName = Foo::CallbackName

notice this will still work even if you change number of callback parameters

Sebastian
  • 330
  • 4
  • 9