Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: 'auto' and const references (http://www.velocityreviews.com/forums/t960334-re-auto-and-const-references.html)

SG 05-03-2013 02:56 PM

Re: 'auto' and const references
 
Am 03.05.2013 15:16, schrieb Juha Nieminen:
> Let's say that a function returns a const reference. If I say this:
>
> auto x = thatFunction();
>
> what would the type of 'x' be? Will it be a const reference, thus
> eliding copying, or will a copy be made?


No, it's not. It's like template argument deduction for a parameter "T
x" where you pass in thatFunction(); as argument. So, x won't be a
reference.

> Is there any difference to these:
>
> auto& x = thatFunction();
> const auto& x = thatFunction();


Sure. But I think you can figure it out now.

HTH,
SG


All times are GMT. The time now is 10:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.