mardi 5 avril 2016

Using auto for all variables in C++ [duplicate]

This question already has an answer here:

Kind of a noobish question. However, I am genuinely curious:

The auto keyword took on a whole new meaning starting with C++ 11 when Type Inference was introduced (or improved) - it works sort of like implicit types using var in C#.

Is there any reason not to leave it up to the compiler to infer the type and make all of your variables auto?

Obviously declaring them yourself allows you to know for certain what the type is going to be, but is there any technical reason not to exclusively use auto now?

The only time I can see explicit declaration being a must is when using templates.

Aucun commentaire:

Enregistrer un commentaire