所以我试图创建一个模拟医院病房的类 Room,但它一直在我的构造函数中给我一个错误。有时没有问题,但随后又回来了......这里的其他用户定义对象包括没有问题的 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 =
};
和菲律宾共产党
#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-stylecast or type Construction
我不知道发生了什么事
您显然忘记包含定义的标头Patient
:
#include "Patient.h"
或类似的。
Also,
patient= Patient();
是多余的,成员patient
默认情况下将进行值初始化,并且
Room::Room();
不正确 - 您没有提供实现。
Next, 你的设计似乎有缺陷。您似乎暗示患者是房间的一部分,并选择了构图来做到这一点。但事实并非如此。如果房间是空的怎么办?您当前的设计尚未处理这种情况。
编辑:您的意思是:
return !(*this == other);
在你的超载中operator!=
?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)