C++ typedef member function signature syntax

后端 未结 5 1708
清酒与你
清酒与你 2020-12-23 17:22

I want to declare type definition for a member function signature. Global function typedefs look like this:

typedef int (function_signature)(int, int);
typed         


        
5条回答
  •  梦毁少年i
    2020-12-23 17:59

    It works for me:

    #include 
    
    class foo
      {
    public:
      int g (int x, int y) { return x + y ; }
      } ;
    
    typedef int (foo::*memberf_pointer)(int, int);
    
    int main()
      {
      foo f ;
      memberf_pointer mp = &foo::g ;
      std::cout << (f.*mp) (5, 8) << std::endl ;
      }
    

提交回复
热议问题