声明对象数组

Declaring an array of objects

本文关键字:数组 对象 声明      更新时间:2023-10-16

我必须创建一个对象数组,但我的类中也有一个参数化构造函数,它对类的属性进行一些初始化。如何在c++中做到这一点?

是否有"正常"初始化列表?

示例:

struct S
{
    S(int, const std::string&) {}  // Just a dummy constructor
};
S array_of_s[2] = {
    S(123, "foo"),
    S(456, "bar")
};