I would like to make a dynamic array of a class with a constructor that has paramaters.
Where does the constructor's size parameter go?
ex. twoDArrayInDisguise = new dynamicArray(size)*[size];
Does not work
I would like to make a dynamic array of a class with a constructor that has paramaters.
Where does the constructor's size parameter go?
ex. twoDArrayInDisguise = new dynamicArray(size)*[size];
Does not work
You cannot do this directly (when using new[]
, the default constructor is used).
Instead, use a std::vector
. You can initialise each element in terms of a reference object, e.g.:
std::vector<T> vec(size, T(/* args */));
In C++, you cannot dynamically create an array of a class with a constructor that has paramaters!