7

How can I describe a map of lambda? I want to have a map of lambda which will be called on event (just as a simple callback). The lambda type is constant.

4

1 回答 1

19

使用<functional>标题和std::function模板类。这允许您指定具有固定方法签名的函数对象。

std::map< unsigned int, std::function<int(int,int)> > callbackMap;

假设您使用 索引回调unsigned int,上面的映射存储了接受两个int并返回的函数int

于 2012-04-24T08:08:18.650 回答