Reputation: 11
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
Upvotes: 1
Views: 874
Reputation: 272507
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 */));
Upvotes: 5
Reputation: 361442
In C++, you cannot dynamically create an array of a class with a constructor that has paramaters!
Upvotes: 1