我有一个指向对象的指针数组
Room *rooms[MAX_ROOMS];
rooms[0] = new Room(101, 1, RT_CLASSIC, 200.00);
rooms[1] = new Room(102, 2, RT_CLASSIC, 280.00);
rooms[2] = new Room(103, 4, RT_FAMILY_SUITE, 360.00);
Class Room有一个重载的友元运算符 <<:
std::ostream& operator<<(std::ostream &out, const Room &room) {
return out << room.toString();
}
如何像这样输出房间数组:
for(int i = 0; i < num_of_rooms; i++) {
cout << rooms[i] << "\n";
}
因为现在它将地址输出到Room对象。我需要它来调用我的Room << 操作员。
谢谢您的回答。