I wanted to know how can the initializer list constructors be implemented if I want to make my own vector class?
eg:
Vector_Class<int> v{1, 2, 3, 4, 5};
How can this type of constructor be implemented?
I wanted to know how can the initializer list constructors be implemented if I want to make my own vector class?
eg:
Vector_Class<int> v{1, 2, 3, 4, 5};
How can this type of constructor be implemented?
You declare a constructor that takes a std::initializer_list<some_type>.
Example:
#include <iostream>
#include <initializer_list>
template<class T>
class foo {
public:
foo(std::initializer_list<T> Ts) {
for(auto v : Ts) {
std::cout << v << '\n';
}
}
};
int main() {
foo<int> x{1,2,3,4,5};
}
Output:
1
2
3
4
5