升压::绑定&具有部分参数的 boost::function
我向您发布了我想要做的事情的示例,以这种方式更容易解释
void myPrinter(const char* text, int number){
printf("\n%s %d\n", 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
}
任何想法吗?
I post you an example of what I want to do, that is easier to explain in this way
void myPrinter(const char* text, int number){
printf("\n%s %d\n", 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
}
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
跳过这个论点。
这仅绑定第一个参数。
如果您只想绑定第二个,则需要一个占位符:
Just skip that argument.
This binds only the first argument.
If you wanted to bind only the second one, you would need a placeholder: