There is a class Array<T> .
Example of use:
Array<string> a; a.add("test"); a.add("..."); //... How do I implement the initialization option
Array<string> a = {"str1", "str2"}; ?
There is a class Array<T> .
Example of use:
Array<string> a; a.add("test"); a.add("..."); //... How do I implement the initialization option
Array<string> a = {"str1", "str2"}; ?
Taken here http://www.bogotobogo.com/cplusplus/C11/C11_initializer_list.php
In general, you need to write something
Array(const std::initializer_list<T> &v) { for (auto itm : v) { add(itm); } } (since you have templates there, you need to take this into account. But your code is not there, therefore there is no guarantee for compilation).
auto itm or auto &itm or auto &&itm ? And generally, and it is impossible to shift to compile-time? - Qwertiy ♦initializer_list<T> must be passed by value, and certainly not by a constant link. - AbyxYou can do the same as the stl developers in std::array
template<class T, int size> class Array{ public: T data[size]; //... }; Array<std::string, 10> arr = {"1", "2", "3"}; Source: https://ru.stackoverflow.com/questions/612992/
All Articles