Function pointer to class member function

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

    What you probably want is this:

    #include 
    #include 
    using namespace std;
    
    class test{
    
    public:
        test(){};
    
        double tt(double input){
            return input;
        };
    
    };
    
    double fptr_test( std::function func, double input){
        return func(input);
    }
    
    
    int main(){
        using namespace std::placeholders;
    
        test t;
        cout << t.tt(3) << endl;
        cout << fptr_test( std::bind( &test::tt, t, _1 ), 3) << endl;
    
        return 0;
    }
    

    Btw - when your program finishes correctly you suppose to return 0 from main()

提交回复
热议问题