如何称呼…… else 除了 class 的默认构造函数和 new[] - 运算符

How to call sth. else beside the default constructor for a class with the new[] - Operator

我怎样才能调用某事。 else then the default constructor to initialize an array of typ Class with the new[]-Operator.

class Class{
...
}

//this only calls the default Constructor of the class
//but I want to initialize the class with my own defined
//constructor passing various arguments to the constructor 

Class* pClass = new Class[100];

感谢和欢呼

塞巴斯蒂安

而不是使用 new,我建议使用 std::vector,然后你可以使用任何你喜欢的构造函数。

例如,如果您有两个版本的构造函数

Class();           // default
Class(int, bool);  // some other

那你可以说

std::vector<Class> classes{100, Class{5, true}};

这将创建一个包含 100 个元素的 vector,每个元素使用您想要的任何参数调用您的参数化构造函数。