Quick Q: Why do 'auto x = my_x;' and 'X& x = my_x;' declare different types? -- StackOverflow

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

Comments are closed.

Comments (0)

There are currently no comments on this entry.