國立暨南國際大學 98 學年度第二學期小考試卷
科目名稱:資訊系統
與網路導論 |
開課系所:資訊工程
學系 |
任課教師
|
吳坤熹
|
系所別:
|
年級:
|
學號:
|
姓名:
|
考試日期
|
2010.3.24
|
(考試時間: 14:10-14:25)
- (10%) Determine whether the following code has syntax erros or
not. If it is correct, predict its output. If it is
incorrect, point out the mistake(s).
//
Ex8_05a.cpp
// Overloaded assignment operator for CBOX objects
#include <iostream>
using std::cout;
class CBox
{
private:
int weight;
public:
void ShowWeight() const
{ cout << weight
<< "\n"; }
CBox(const int w =
0) // Constructor definition
{ weight = w; }
CBox operator=(const
CBox& aBox)
{
if
(this == &aBox) // Check adresses, if equal
return
*this; // return the 1st operand
//
Copy 2nd operand to 1st
weight = aBox.weight;
return *this;
}
};
int main()
{
CBox box1(10);
CBox box2;
CBox box3(box1);
(box3 = box2) = box1;
box3.ShowWeight();
box3 = box2 = box1;
box3.ShowWeight();
return 0;
}