Answer the question
In order to leave comments, you need to log in
C++11, C++14. Is using auto a sign of bad taste?
C++11 and 14 brought a lot of new goodies. It so happened that I started dealing with them quite recently.
For example auto in a function declaration. It seems to me that this may not be a good thing at all.
auto Func()
{
// ...
int a=0;
// код код и еще код
// ...
return a+1;
}
// ...
// Где нибудь внизу
auto var=Func();
// ...
Answer the question
In order to leave comments, you need to log in
Such good advice here...
And the rule is nowhere simpler: if you ALREADY have enough information to work with the value without specifying the type, then you can use auto. If you feel that you do not have, or doubt that you have, it is better to indicate the type. An example where using auto is great is iterators:
std::list<int> items;
auto i = items.cbegin();
std::list<int>::const_iterator
will not bring me any new information. Moreover, because Because since since iterators from different containers are incompatible, I also need to know right away which specific list I have an iterator for - I will again look at items.cbegin, and not at the type.Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question