我正在使用给定类的动态数组,我们将其称为“ MyClass”,问题是此类具有带有给定参数的专用构造函数。
据我所知初始化动态数组,我应该使用此:
MyClass *myArray = new MyClass[]();
有没有一种方法可以使用我的专用构造函数来初始化我的数组?就像是:
MyClass *myArray = new MyClass[](givenParameter);
and this got me to another question, what does the line MyClass *myArray = new MyClass[]();
is it calling a base constructor without any given parameters or does it do something else internally?
这可能很明显,但我无法在此上找到很多信息,至少不能解决我的第一个问题。谢谢大家。
我不确定还有另一种用非标准构造函数初始化C数组的方法。
但是如果您可以使用std :: vector则可以: