Function pointer to class member function

后端 未结 4 1789
既然无缘
既然无缘 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:51

    Here is a code after modification.

    #include 
    using namespace std;
    
    class test{
    
    public:
        test(){};
    
        double tt(double input){
            return input;
        };
    
    };
    
    double fptr_test(test* t, double (test::*fptr)(double), double input){
        return (t->*fptr)(input);
    }
    
    int main(){
    
        test t;
        cout << t.tt(3) << endl;
        cout << fptr_test(&t, &test::tt, 3) << endl;
    
        return 1;
    }
    

提交回复
热议问题