#include <iostream>
#include <initializer_list>
class MyArray {
int* array;
public:
MyArray(){}
MyArray(std::initializer_list<int>& v) {
array = new int[v.size()];
int index = 0;
for (auto element : v) {
array[index] = element;
index++;
}
}
~MyArray()
{
delete[] array;
}
};
int main() {
MyArray object{ 2,4,2,2 };
}
This is my first time working with std::initializer for object list initialization. I have created a an array that is initialized using the MyArray constructor. i don't know where am i going wrong. i created an object that matches the argument list, ie a constructor that takes an initializer list.