我想知道是否可以将其放入数组中,以便将同一内容打印三遍?
ChineseFireball dragon = ChineseFireball("Scarlet", "Beast", "China", 6, 25);
dragon.print();
最佳答案
/* Populate */
ChineseFireball dragons[3];
for (int i = 0; i < 3; i++)
{
dragons[i] = ChineseFireball("Scarlet", "Beast", "China", 6, 25);
}
/* Print */
for (int i = 0; i < 3; i++)
{
dragons[i].print();
}
如果不需要数组:
ChineseFireball dragon = ChineseFireball("Scarlet", "Beast", "China", 6, 25);
for (int i = 0; i < 3; i++)
{
dragon.print();
}
关于c++ - 创建一个Class对象数组并用C++打印它们?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42238887/