本文介绍了如何TR1 ::的reference_wrapper有用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我一直在通过斯科特迈尔斯的出色的电​​子书阅读。在过去的秘诀之一,他所涵盖的一些功能从TR1 - 我通过升压知道很多。

recently I've been reading through Scott Meyers's excellent Effective C++ book. In one of the last tips he covered some of the features from TR1 - I knew many of them via Boost.

不过,有一个,我是绝对不承认:TR1 ::的reference_wrapper。

However, there was one that I definitely did NOT recognize: tr1::reference_wrapper.

如何及何时我会用TR1 ::的reference_wrapper?

How and when would I use tr1::reference_wrapper?

推荐答案

这就像升压::裁判,因为据我所知。基本上,参考其可以被复制。绑定到你需要按引用传递参数的函数时非常有用的。

It's like boost::ref, as far as I know. Basically, a reference which can be copied. Very useful when binding to functions where you need to pass parameters by reference.

例如(使用升压语法):

For example (using boost syntax):

void Increment( int& iValue )
{
    iValue++;
}

int iVariable = 0;
boost::function< void () > fIncrementMyVariable = boost::bind( &Increment, boost::ref( iVariable ));

fIncrementMyVariable();

,有一些信息。

希望这是正确的,有益的。 :)

Hope this is right, and helpful. :)

这篇关于如何TR1 ::的reference_wrapper有用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 11:03