class book{
private:
int numOfPages;
public:
book(int i){
numOfPages = i;
};
};
class library{
private:
book * arrOfBooks;
public:
library(int x, int y){
arrOfBooks = new book[x](y);
};
};
int main()
{
library(2, 4);
};
使用上面的示例代码,我想创建一个具有相同页数的图书库。因此,在库对象的构造函数中,每当创建要放置在数组中的新书时,我都会在括号中传递参数。上面的代码在C++ shell中测试时显示错误:“array new 中的带括号的初始化程序”。这是为了完成一个学校项目,不允许使用向量(因为我发现这样做是明智的)尽管我想不出除了上面显示的方法之外的任何其他方法......