At the beginning I would like to explain you one small new feature of C++11 standard. This feature is auto type.
auto is new C++11 type keyword which automatically deducts type of variable.
See example below:
What is type of variable b? int of course. C++11 can automatically deduct type of variables using auto type. However remember - there is not desirable to use auto too often. It can make your code less readable. Try to use defined types as often as possible.
Nevertheless, there is little more useful example of usage auto type. Let say that we have been declared following map containing two strings as key-value instances:
Now if we would like to iterate through elements of above map in previous version of C++ (C++03) we had to declare iterator following way for example:
Thanks to auto type C++11 allow us to declare it that way:
Shorter and more comfortable.
That's it for the beginning. I hope you understand usage auto type in C++11 right now. Write your proposition of other ways of usage auto type in comments, please.
auto is new C++11 type keyword which automatically deducts type of variable.
See example below:
What is type of variable b? int of course. C++11 can automatically deduct type of variables using auto type. However remember - there is not desirable to use auto too often. It can make your code less readable. Try to use defined types as often as possible.
Nevertheless, there is little more useful example of usage auto type. Let say that we have been declared following map containing two strings as key-value instances:
Now if we would like to iterate through elements of above map in previous version of C++ (C++03) we had to declare iterator following way for example:
Thanks to auto type C++11 allow us to declare it that way:
Shorter and more comfortable.
That's it for the beginning. I hope you understand usage auto type in C++11 right now. Write your proposition of other ways of usage auto type in comments, please.
Comments
Post a Comment