Member-Function Pointers With Default Arguments

后端 未结 4 1526
走了就别回头了
走了就别回头了 2021-01-03 01:03

I am trying to create a pointer to a member function which has default arguments. When I call through this function pointer, I do not want to specify an argument for the de

4条回答
  •  太阳男子
    2021-01-03 01:33

    You could create functors instead of function pointers of course.

    struct MyFunctor {
        int operator() {
            return myobj.bar();
        }
    
        MyFunctor(MyObj &obj) : myobj(obj) {}
        MyObj &myobj;
    };
    

    then:

    MyFunctor myfunc(o);
    myFunctor();
    

提交回复
热议问题