【发布时间】:2015-07-11 16:02:37
【问题描述】:
我一直在查看一些 Boost 源代码并注意到它们通过使用仿函数而不是普通函数来实现模板化函数?这是有原因的吗?
例如:
template<typename Foo, typename Bar>
struct functor {
Bar operator()(const Foo& foo) {
return foo.as_bar();
}
};
相对于:
template<typename Foo, typename Bar>
Bar func(const Foo& foo) {
return foo.as_bar();
}
我能想到的唯一优点是它允许类继承函数?
【问题讨论】:
标签: c++ function templates functor