Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 });
27th Mar 2017, 4:30 AM
Squidy
Squidy - avatar