I just started playing around with the auto
keyword of the new C++ standard. I assumed a variable declared with auto
would have the type of the according expression.
Though consider the following example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Looking at the variables in the debugger, you see that data
contains the values 1
and 2
, whereas data2
only contains 1
, thus data2
is not the same object as data
. I assumed data2
was of type vector<int>&
(the return type of getData
), though it obviously just is vector<int>
.
Declaring it as
1
|
|
works though. data2
is now a reference to data
.
It makes sense, the standard defines it that way. Otherwise, how could you create a copy of the return value? Still it makes using auto
a little more confusing …