预期'('对于函数式铸造或类型构造 [英] Expected '(' for function-style cast or type construction
问题描述
所以我试图创建一个类房间模拟一个医院的房间,但它一直给我一个错误在我的构造函数。有时没有问题,但它回来....其他用户定义的对象在这里包括没有问题的Patient类和一个也没有问题的LinkedList模板类。
以下是标题
class Room
{
public:
Room();
Room(int);
static LinksList< Room> createRooms();
病人;
int roomNumber;
bool operator ==(const Room& other)const; // overload ==
bool operator!=(const Room& other)const; // overload!=
void operator =(const Room& other)const; // overload =
};
和cpp
#includeRoom.h
房间::房间();
Room :: Room(int n)
{
roomNumber = n;
patient = Patient();
}
LinkedList< Room> Room :: createRooms(){
//创建房间直到达到房间
LinkedList< Room> roomList;
for(int i = 1; i <11; i ++){
房间=房间(100 + i);
roomList.push(room);
}
return roomList;
}
//重载==
bool Room :: operator ==(const Room& other)const {
//比较每个房间的房号字段
return(this-> roomNumber == other.roomNumber&& this-> patient == other.patient);
}
//重载!=
bool Room :: operator!=(const Room& other)const {
return!其他);
}
void Room :: operator =(const Room& other)const {
this-> patient = other.patient;
this-> roomNumber = other.roomNumber;
}
问题是Room(int)构造函数。 Xcode不断地给我一个消息说Expected(用于函数式转换或类型构造)
我不知道发生了什么
$ b $ b
#includePatient.h
此外,
patient = Patient
是多余的,成员病人
value-initialized by default,and
Room :: Room();
/ pre>
不正确 - 您未提供实施。
设计看起来有缺陷。你似乎暗示一个病人是房间的一部分,并选择组合来做到这一点,但它不是,如果房间是空的,如果你的当前设计还没有处理。
编辑:您的意思是:
== other);
重载到
operator!=
?So I'm trying to create a class Room that simulates a hospital room but it keeps giving me an error in my constructor. Sometimes there's no issue but then it comes back....other user defined objects here include a Patient class that has no problems and a LinkedList template class that also has no issues.
Here's the header
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 = };
and the 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; }
the problem is with the Room(int) constructor. Xcode keeps giving me a message saying Expected '(' for function-style cast or type construction
I have no idea what's going on
解决方案You clearly forgot to include the header that defines
Patient
:#include "Patient.h"
or similar.
Also,
patient= Patient();
is redundant, the member
patient
will be value-initialized by default, andRoom::Room();
is not correct - you're not providing an implementation.
Next, your design seems flawed. You seem to imply that a patient is part of a room, and chose composition to do so. But it's not. What if the room is empty? Your current design doesn't yet treat that case.
EDIT: did you mean:
return !(*this == other);
in your overload to
operator!=
?这篇关于预期'('对于函数式铸造或类型构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!