您可以通过多种选择来实现C ++中的委托。这是我想到的那些。选项1:函子:可以通过实现来创建功能对象 operator()struct Functor{ // Normal class/struct members int operator()(double d) // Arbitrary return types and parameter list { return (int) d + 1; }};// Use:Functor f;int i = f(3.14);选项2:lambda表达式(仅C ++ 11)// Syntax is roughly: [capture](parameter list) -> return type {block}// Some shortcuts existauto func = [](int i) -> double { return 2*i/1.15; };double d = func(1);选项3:函数指针int f(double d) { ... }typedef int (*MyFuncT) (double d);MyFuncT fp = &f;int a = fp(3.14);选项4:指向成员函数的指针(最快的解决方案)请参见Fast C ++ Delegate(在The Code Project上)。struct DelegateList{ int f1(double d) { } int f2(double d) { }};typedef int (DelegateList::* DelegateType)(double d);DelegateType d = &DelegateList::f1;DelegateList list;int a = (list.*d)(3.14);选项5:std :: function(或者boost::function如果您的标准库不支持它)。它比较慢,但是最灵活。#include <functional>std::function<int(double)> f = [can be set to about anything in this answer]// Usually more useful as a parameter to another functions选项6:绑定(使用std :: bind)允许预先设置一些参数,例如方便调用成员函数。struct MyClass{ int DoStuff(double d); // actually a DoStuff(MyClass* this, double d)};std::function<int(double d)> f = std::bind(&MyClass::DoStuff, this, std::placeholders::_1);// auto f = std::bind(...); in C++11选项7:模板接受与参数列表匹配的任何内容。template <class FunctionT>int DoSomething(FunctionT func){ return func(3.14);}