I have created a class that should act as a collection (with some custom behavior of mine). Inside, the class contains an array, to store the values.
class MyCollection {
private:
int m_array[N];
public:
int operator [] (int idx) const {
return m_array[idx];
}
int operator [] (TKey k) {
return m_array[idx];
}
};
I would like to be able to initialize an instance of this class like it can be done with arrays, but I don't know how to do it, or what this kind of initialization is called ot then look on the web.
std::array<int, 3> a2 = {1, 2, 3};
How can this be achieved?
Please note that I may change the type of the elements of the collection (even template it), the referred int
is just an example.