Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
An initializer-list is on option that can be used, depending
on the standard used:
initializer list is not supported in C++98.
Compiler output:
/MyFolder/main.cpp:5: error: in C++98 'v' must be initialized by constructor, not by '{...}'
/MyFolder/main.cpp:5: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
/MyFolder/main.cpp:5: error: deducing from brace-enclosed initializer list requires #include <initializer_list>
/MyFolder/main.cpp:5: error: no matching function for call to 'std::vector<int, std::allocator<int> >::vector(<brace-enclosed initializer list>)'
/usr/include/c++/4.4/bits/stl_vector.h:241: candidates are: std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = int, _Alloc = std::allocator<int>]
/usr/include/c++/4.4/bits/stl_vector.h:207: std::vector<_Tp, _Alloc>::vector() [with _Tp = int, _Alloc = std::allocator<int>]
|
An initializer list is an additional initialization option:
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 17.7. Advice. page 525: '[8] If a class is a container, give it an initializer-list constructor'
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.
