// Functoional.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 #include <iostream> #include <functional> using namespace std; typedef void(*f)(int); typedef void(*FuncVoid)(void); void Print() { cout << "print" << endl; } void Print(int a) { cout << "print" << a << endl; } class Fun { public: void Print() { cout << "print" << endl; } void Print(int a) { cout << "print" << a << endl; } }; int main() { FuncVoid fv; fv = Print; fv(); void(); //std::function<void()> func = std::bind<void()>(Print); //同名函数重载 std::function<void()> func = bind((FuncVoid)Print); std::function<void(int)> func2 = bind((void(*)(int))Print, placeholders::_1); Fun f; std::function<void()> func3 = bind((void(Fun::*)())&Fun::Print, f); std::function<void(int)> func4 = bind((void(Fun::*)(int))&Fun::Print, f, std::placeholders::_1); func(); func2(3); func3(); func4(4); cout << "func c" << endl; return 0; }