Search code examples
c++typedefusing-declaration

How do I template a function typedef using an alias declaration?


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.


Solution

  • 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);