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, eg:
std::vector<T> vec(size, T(/* args */));
在C ++中,不能使用具有参数的构造函数动态创建类的数组!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.