std::function::operator()
来自cppreference.com
< cpp | utility | functional | function
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
R operator()( ArgTypes... args ) const; |
(C++11 起) | |
Calls the stored callable function target with the parameters args
.
目录 |
[编辑] 参数
args | - | parameters to pass to the stored callable function target |
[编辑] 返回值
None if R
is void. Otherwise the return value of the invocation of the stored callable object.
[编辑] 例外
- std::bad_function_call if *this does not store a callable function target, !*this == true.
[编辑] 示例
The following example shows how std::function can passed to other functions by value. Also, it shown how std::function can store lambdas.
#include <iostream> #include <functional> void call(std::function<int()> f) // can be passed by value { std::cout << f() << '\n'; } int normal_function() { return 42; } int main() { int n = 1; std::function<int()> f = [&n](){ return n; }; call(f); n = 2; call(f); f = normal_function; call(f); }
输出:
1 2 42
[编辑] 另请参阅
本章尚未完成 |