所以我正在尝试创建一个模拟医院病房的教室,但它一直在我的构造函数中给我一个错误。有时没有问题,但随后又回来了....此处的其他用户定义对象包括没有问题的 Patient 类和也没有问题的 LinkedList 模板类。
这是标题
class Room
{
public:
Room();
Room(int);
static LinkedList<Room> createRooms();
Patient patient;
int roomNumber;
bool operator==(const Room &other) const; //overload ==
bool operator!=(const Room &other) const; //overload !=
void operator=(const Room &other) const; //overload =
};
和 cpp
#include "Room.h"
Room::Room();
Room::Room(int n)
{
roomNumber= n;
patient= Patient();
}
LinkedList<Room> Room::createRooms() {
//create rooms up until ROOMS is reached
LinkedList<Room> roomList;
for(int i= 1; i < 11; i++){
Room room= Room(100+i);
roomList.push(room);
}
return roomList;
}
//Overload ==
bool Room::operator==(const Room &other)const{
//compare each room's room number field
return (this->roomNumber == other.roomNumber && this->patient == other.patient);
}
//Overload !=
bool Room::operator!=(const Room &other)const{
return !(this == &other);
}
void Room::operator=(const Room &other)const{
this->patient= other.patient;
this->roomNumber= other.roomNumber;
}
问题出在 Room(int) 构造函数上。Xcode 不断给我一条消息,说 Expected '(' for function-style cast or type construction
我不知道是怎么回事