I am starting picking up c++11 and at this point I have a love-n-hate of "auto".
No doubt it is convenient.
But it is also confusing, here is a code:
auto w = foo->get_w();
auto i = w->get_i();
bar(i);
In this code, get_w()
function returns "struct S*" which is w's type. But struct S has 2 overloaded get_i():
const I* get_i() const;
unique_ptr<I>& get_i();
Because w is not const
, so it is the 2nd get_i()
gets called, and thus bar(i)
should be bar(move(i))
because bar() signature is void bar(unique_ptr<I>)
.
But in reality, it is easy to get track lost.
It is good that this is caught in compile time, but, i guess, my initial enthusiasm is waning.
How do you think? Any tip?