码迷,mamicode.com
首页 > 其他好文 > 详细

仿函数(functor)

时间:2018-03-27 12:36:35      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:ict   roc   rect   science   一个   fun   ade   com   const   

仿函数(functor),就是使一个类的使用看上去像一个函数。其实现就是类中实现一个operator(),这个类就有了类似函数的行为,就是一个仿函数类了。

 

In computer programming, a function object[a] is a construct allowing an object to be invoked or called as if it were an ordinary function, usually with the same syntax (a function parameter that can also be a function). Function objects are often called functors.

 

A typical use of a function object is in writing callback functions. A callback in procedural languages, such as C, may be performed by using function pointers.[2] However it can be difficult or awkward to pass a state into or out of the callback function. This restriction also inhibits more dynamic behavior of the function. A function object solves those problems since the function is really a fa?ade for a full object, carrying its own state.

仿函数(functor)

标签:ict   roc   rect   science   一个   fun   ade   com   const   

原文地址:https://www.cnblogs.com/feng9exe/p/8656292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!