[try Beta version]
Not logged in

 
 
Help with &&

Oct 30, 2014 at 9:30pm
Hi, I was looking at the tutorial of the function template std::make_pair. I don't recognize what the symbol && following the arguements type means. Does it mean reference? What is the difference between using & and && here?

1
2
  template <class T1, class T2>
  pair<V1,V2> make_pair (T1&& x, T2&& y);
Oct 30, 2014 at 10:05pm
Yes, this means reference. Specifically, a reference to a reference.
Oct 30, 2014 at 10:09pm
It allows you to do such things as this without the object being destroyed.

make_pair("x", Object(arg1, arg2, ...))
Oct 30, 2014 at 10:10pm
It is an rvalue reference; I am too lazy to type up a good explanation so you can try reading this stackoverflow post I googled:
http://stackoverflow.com/questions/5481539/what-does-t-double-ampersand-mean-in-c11
Oct 30, 2014 at 11:24pm
Thank you, Zhuge! The webpage you suggested is very helpful! I understand what double ampersand means now!

To Ispil: Thank you. But I'm not really sure if there is something like a reference to a reference in C plus plus? I mean, how can we make a reference pointing to another reference? References are quite different from pointers. They need to be initialized at declaration. After declaration, they are exactly the same as what they refer to. In other words, there is no dereferencing for references.
Oct 31, 2014 at 12:07am
Indeed. In that case, I was mistaken.
Topic archived. No new replies allowed.