boost :: bind与具有引用的参数的函数 [英] boost::bind with functions that have parameters that are references

查看:438
本文介绍了boost :: bind与具有引用的参数的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当传递引用参数到boost绑定时,这些参数将不会像引用一样。相反,boost会创建成员的另一个副本,并且在变量中传递的原始值保持不变。

I noticed that when passing reference parameters to boost bind, those parameters won't act like references. Instead boost creates another copy of the member and the original passed in variable remains unchanged.

当我改变指针的引用时,一切正常。

When I change the references to pointers, everything works ok.

我的问题是:

是否可以获取引用的工作,或者至少在尝试使用引用参数时给出编译错误?

Is it possible to get references to work, or at least give a compiling error when it tries to use reference parameters?

推荐答案

bind的文档建议您可以使用boost :: ref和boost :: cref。

The boost documentation for bind suggests that you can use boost::ref and boost::cref for this.

这篇关于boost :: bind与具有引用的参数的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆