Use a vector.
class myClass {
private:
std::vector<int> myArray;
public:
myClass();
someOtherMethod();
};
myClass::myClass (int size)
: myArray (size)
{
...
}
Then you can fill the vector in the same way as an array. Alternatively, as Nawaz points out, use reserve()one that reserves space for new items and / or push_back()that adds items to the back one at a time.
chris source
share