Can C++11 decltype be used to create a typedef for function pointer from an existing function?

前端 未结 2 1073
谎友^
谎友^ 2021-02-03 20:02

Given

struct A { 
    int foo(double a, std::string& b) const;
};

I can create a member function pointer like this:

typedef         


        
2条回答
  •  你的背包
    2021-02-03 20:51

    Yes, of course:

    typedef decltype(&A::foo) PFN_FOO;

    You can also define type alias via using keyword (Thanks to Matthieu M.):

    using PFN_FOO = decltype(&A::foo);

提交回复
热议问题