使用c++11的function函数绑定参数个数不同的成员函数



#ifndef __FUNCTIONBIND__H
#define __FUNCTIONBIND__H
#include 
#include 

class CBindFunction
{
public:
    CBindFunction() = default;
    ~CBindFunction() = default;

public:
    void Print()
    {
        std::cout << "Print" << std::endl;
    }       
    void PrintPtr(void* arg, int nLen)
    {
        std::cout << "PrintPtr" << std::endl;
    }
};

typedef std::function<void(void*)> func;

int main()
{
    CBindFunction obj;
    func call = std::bind(&CBindFunction::Print, &obj);
    call(NULL); // Print
    call = std::bind(&CBindFunction::PrintPtr, &obj, nullptr, 0);
    call(NULL); // PrintPtr;
}

#endif

你可能感兴趣的:(c++,c++,c++11)