Quick Q: Why do ‘auto x = my_x;’ and ‘X& x = my_x;’ declare different types?—StackOverflow

Save to:
Instapaper Pocket Readability

Quick A: Remember that you can add things like const and & to an auto type...

'auto' and explicit variable declaration behaving differently

I have something like this:

[...]

auto bar1 = foo.GetBar();
auto bar2 = foo.GetBar(); //address of bar2 != address of bar1. why?

Bar& bar3 = foo.GetBar();
Bar& bar4 = foo.GetBar(); //address of bar3 == address of bar4.

What's going on here?

Add a Comment

You must sign in or register to add a comment.

Comments (0)

There are currently no comments on this entry.