Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Declaring a variable as a const reference

20 views
Skip to first unread message

Paul

unread,
Jan 15, 2017, 7:57:08 AM1/15/17
to
Is there ever a time when it is good practice to write


int main()
{

const someType& = // ....
}

or int main()
{

const int& x = 7;
}

I know through testing that the latter example compiles but I've never
seen this used.

Thanks,

Paul

Bo Persson

unread,
Jan 15, 2017, 1:10:54 PM1/15/17
to
The first example might be useful if the someType object exist elsewhere
and you don't want to copy it.

Avoiding a copy for the value 7 though, seems less than useful.



Bo Persson


0 new messages