What happens in the example in this article is using the {}-initialization introduced by C++11 and that doesn't involve any arrays. Instead what you have on the right side is std::initializer_list and you use constructor #10 of vector: https://en.cppreference.com/w/cpp/container/vector/vector.
Sadly many articles on the net make the very same mistake (I guess one inspires the others).
Before I forget, vector does have a maximum size that's why there is max_size() that you also referenced.
B2C Technical Content Marketing / Blog Team Lead for Educative.io (she/her)
Sign up for our blog newsletter here: https://www.educative.io/blog/blog-newsletter-annoucement
Nice summary. A few comments:
You can initialize a vector from an array, but that's not what happens at "1. Using an array".
If you want to show how to initialize a vector from an array, look at this example:
What happens in the example in this article is using the
{}
-initialization introduced by C++11 and that doesn't involve any arrays. Instead what you have on the right side isstd::initializer_list
and you use constructor #10 of vector:https://en.cppreference.com/w/cpp/container/vector/vector
.Sadly many articles on the net make the very same mistake (I guess one inspires the others).
Before I forget,
vector
does have a maximum size that's why there is max_size() that you also referenced.Thank you for this information, Sandor! I appreciate it.