pointer to const member function typedef

前端 未结 3 1676
长情又很酷
长情又很酷 2021-01-01 11:36

I know it\'s possible to separate to create a pointer to member function like this

struct K { void func() {} };
typedef void FuncType();
typedef FuncType K::         


        
3条回答
  •  梦毁少年i
    2021-01-01 12:13

    A slight refinement showing how to do it without a typedef. In a deduced context like the following, you can't use a typedef.

    template 
    Field extract_field(const Class& obj, Field (Class::*getter)() const)
    {
       return (obj.*getter)();
    }
    

    applied to some class with a const getter:

    class Foo {
     public:
      int get_int() const;
    };
    
    Foo obj;
    int sz = extract_field(obj, &Foo::get_int);
    

提交回复
热议问题