samedi 3 octobre 2015

What does auto always deduce the basic type mean here

I was reading this article which states

that

widget w = get_gadget(); -->a
auto w = get_gadget();   -->b

in statement 'a' a temporary is created then widget w is move constructed from the temporary. I totally understand that statement. What I don't understand is how statement 'b' using the auto variable is better than statement 'a'. It says

.... we could write the following which guarantees there is no implicit conversion because auto always deduces the basic type exactly:

// better, if you don't need an explicit type

auto w = get_gadget();

Could anyone please explain why statement 'b' is better than 'a' ?

Aucun commentaire:

Enregistrer un commentaire