Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是一名 C++ 开发人员。最近,我遇到了函数对象的概念。但我想知道函数对象在日常编码中的用法。请对这种用法有所了解,这将使代码更清晰或更高效。
这个词的 C++ 含义中的函子使 C++ 2011 中引入的 lambda 的闭包行为成为“可能”。
函子主要用于处理事件。
例如,一个 Event 对象将具有 functors 属性。当事件被触发时,函子指向的函数将被执行。
另一个例子:你有一个 Plot 对象允许绘制曲线。您可以给函子参数,whick 指向允许计算曲线点的函数。