0

Why this is allowed:

int a = 0;
auto&& b = a;

while this is not:

int a = 0;
int&& b = a;

I understand that an l-value cannot be bound to an r-value reference, so why (or how) in this specific case auto&& differs from int&& ?

SeventhSon84
  • 364
  • 1
  • 4
  • `int&&` and `T&&` are two different things – Useless Apr 29 '20 at 12:13
  • I know I wanted to generalize with T I mean every kind of defined type. – SeventhSon84 Apr 29 '20 at 12:15
  • 2
    `int&&` is an `rvalue` while `auto&&` is a `forwarding` reference. Reference collapsing takes place for `auto&&` while `int&& b` is expecting a `rvalue` reference. If you cast `a` to an `rvalue` it'll work – WBuck Apr 29 '20 at 12:15
  • 2
    Does this answer your question? [Syntax for universal references](https://stackoverflow.com/questions/14302849/syntax-for-universal-references) (`auto&&` is basically `template ` + `T&&`) – L. F. Apr 29 '20 at 12:15

0 Answers0