我爲operator=
重載了我創建的類。我爲兩個班級做了這個工作,其中一個工作得很好,他們都看起來是正確的。其中一個重載操作符不起作用。該程序不會產生任何錯誤,只是簡單地返回一個空白版本的類。如果任何人有任何想法可能是什麼問題,將不勝感激。重載=運算符
.h文件中
Patient operator=(const Patient &right);
.cpp文件
//Overloaded functions
Patient Patient::operator=(const Patient &right)
{
Patient temp;
temp.patientName = right.patientName;
temp.age = right.age;
temp.code = right.code;
temp.problem = right.problem;
temp.doctorName = right.doctorName;
temp.roomNum = right.roomNum;
temp.isWaiting = right.isWaiting;
temp.isComplete = right.isComplete;
return temp;
}
部分它被用於程序的。我意識到隨機輸出消息,我正試圖找到程序中我遇到問題的位置。縮小到pat=p;
聲明。
void Room::setPat(Patient p)
{
cout << "Test" << endl;
cout << p.getName() << pat.getName() << "end";
pat = p;
cout << p.getName() << pat.getName() << "end";
cout << "End Test" << endl;
patUsed = true;
}
你知道op =應該改變「this」對象,而不是一些臨時的? – PlasmaHH 2013-04-11 11:32:25
謝謝你用笑聲開始新的一天。 ':'' – 2013-04-11 11:34:16
除了@PlasmaHH表示,我認爲你也在做其他任務。你需要'p = pat;'這是'p.operator =(pat);' – Mahesh 2013-04-11 11:38:18