#ifndef __FUNCTIONBIND__H
#define __FUNCTIONBIND__H
#include <iostream>
#include <functional>
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++11的function函数绑定参数个数不同的成员函数
最新推荐文章于 2023-03-21 17:07:34 发布