小编Arm*_*ani的帖子

有没有办法访问存储在 C++ 中 std::bind() 返回的函数对象中的参数?

我需要一种方法来分解函数std::bind()模板中返回的函数对象及其参数。

\n

下面的代码片段显示了我想要做的事情:

\n
#include <iostream>\n#include <functional>\n\nvoid foo(int x, double y, char z)\n{\n    std::cout << "x = " << x << ", y = " << y << ", z = " << z << \'\\n\';\n}\n\nint main()\n{\n    auto f = std::bind(foo, 42, 3.14, \'a\');\n    std::cout << "The first argument is: " << std::get<0>(f) << \'\\n\';\n    std::cout << "The second argument is: " << std::get<1>(f) << \'\\n\';\n    std::cout << "The third argument is: " << std::get<2>(f) << \'\\n\';\n}\n
Run Code Online (Sandbox Code Playgroud)\n …

c++ std stdbind c++11

4
推荐指数
1
解决办法
146
查看次数

标签 统计

c++ ×1

c++11 ×1

std ×1

stdbind ×1