Function pointer to class member function

后端 未结 4 1788
既然无缘
既然无缘 2020-12-21 20:02

I want to make function which has function pointer as a parameter.

#include 
using namespace std;

class test{

public:
    test(){};

    do         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 20:41

    If you want to pass a pointer to a member-function, you need to use a member-function-pointer, not a pointer for generic free functions and an object to invoke it on.

    Neither is optional.

    double fptr_test(test& t, double (test::*fptr)(double), double input){
        return t.*fptr(input);
    }
    
    // call like this:
    fptr_test(&test::tt, 3); // Your second try
    

提交回复
热议问题