+ 2
Not 100% sure what you're going for, but here's how I understand it:
class ClassWithArray {
public:
ClassWithArray() {
_array = nullptr;
}
~ClassWithArray() {
if (_array)
delete _array;
}
void Set(std::initializer_list<int> values) {
_array = new int[values.size()];
int index = 0;
for (auto i = values.begin(); i != values.end(); ++i)
_array[index++] = *i;
}
private:
int* _array;
};
The you would use it like:
ClassWithArray obj;
obj.Set({ 1, 2, 3 });