boost::bind & boost::function with partial args
boost::bind & boost::function with partial args
我给你发了一个我想做什么的例子,用这种方式更容易解释
void myPrinter(const char* text, int number){
printf("n%s %dn", text, number);
}
int main() {
char *someText="test";
boost::function<void(int my_number)> functionWithSavedArgs = boost::bind(&myPrinter, someText, ?????);
//then I have to call my function with saved args and give to it only variable "number" like:
int myBeautifulNumber = 2012;
functionWithSavedArgs(myBeautifulNumber);
// echo: test 2012
}
有什么想法吗?
跳过那个参数。
boost::function<void(int my_number)> functionWithSavedArgs
= boost::bind(&myPrinter, someText);
这只绑定第一个参数。
如果你只想绑定第二个,你需要一个占位符:
boost::function<void(int my_number)> functionWithSavedArgs
= boost::bind(&myPrinter, _1, someNumber);
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- cmake如何在fedora工作站中找到boost静态库包
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Boost Graph Library,修复节点大小
- 什么是"#include <boost/functional/hash.hpp> "?
- 基于boost的程序的静态链接——zlib问题
- C++:如何在CLion IDE中安装Boost
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 如何在boost beast http请求中设置http头
- Boost Spirit,获取迭代器内部语义动作
- boost::asio::steady_timer()与sleep()我应该使用哪一个
- boost::asio如何生成多个协同程序,然后加入它们
- 当我尝试使用 sstream 和分面将 Boost Time_duration转换为字符串时,我没有得到所需的格式
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 如何使用boost::具有嵌套结构和最小代码更改的序列化
- 使用Boost Interprocess创建托管共享内存需要很长时间
- c++ boost::bind vs clojure partial function
- boost::bind & boost::function with partial args