科目名稱:程式設計 | 開課系所:資訊工程 學系 | 任課教師 |
吳坤熹 |
||
系所別: |
年級: |
學號: |
姓名: |
考試日期 |
2009.4.15 |
(考試時間: 10:10-10:30)
#include <iostream>
using std::cout;
class CNumber
{
public:
CNumber(int v)
{
cout << "A number is created with value: " << (m_value = v)
<< "\n";
}
int m_value;
};
int main()
{
CNumber a(1);
CNumber* pv1 = new CNumber(2);
CNumber* pv2 = new CNumber(3);
cout << "The value of m_value is " << pv2->m_value << "\n";
}
(10%) What output shall we see if we add the following destructor to the above code?
~CNumber()
{
cout << "The object containing " << m_value <<
" is destroyed.\n";
}