3 ms·
>>The next example demonstrates initializing a vector: >> vector<int> v = {1,2,3,5,8,13}; >>This is great, of course. The example after that introduces "au
by npalli 12y ago
>>The next example demonstrates initializing a vector:
>> vector<int> v = {1,2,3,5,8,13};
>>This is great, of course. The example after that introduces "auto" so you don't have to write the type of a variable. Well heck, let's combine the two!
>> auto v = {1,2,3,5,8,13};
The auto example creates an std::initializer_list which then can be converted into a vector or a set
std::vector<int> newvectorfromauto(v);
std::set<int> newsetfromauto(v);
Which seems the best you can expect with auto deduction. What else do you have in mind?
- netheril96 12y agoWhat he has in mind is that it is logical and reasonable for C++ to behave in this way, but completely incomprehensible for beginners who has just learned the basics of programming.