Given the code below, everything works. How come that the variable d is reference to int? What is going on?
int main()
{
int a= 10;
int &&b = a+10; // b is int &&
auto c =b+10; // c is int
auto &&d = a; // d is int&
//int &&di = a; // error, as expected
return (0);
}
This has to do with the reference collapsing rules in type deduction.
A& & becomes A&
A& && becomes A&
A&& & becomes A&
A&& && becomes A&&
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With