我用下面的程序簡單測試了一下全局對象,它在main函數執行前被構造,但什麼時候析構呢? #include <iostream> #include <string> using namespace std;
class Student {public: Student(int n,string nam,char s) {num=n; name=nam; sex=s; cout < < "Constructor called. " < <num < <endl; } ~Student() {cout < < "Destructor called. " < <num < <endl;} private: int num; string name; char sex; };
Student stud1(10010, "Wang_li ", 'f ');
int main() { Student stud2(10011, "Zhang_fun ", 'm '); return 0; }
運行結果: Constructor called.10010 Constructor called.10011 Donstructor called.10011
結果中沒有顯示出全局對象的析構信息,我跟蹤調試時也沒有查到,請問各位全局對象什麼時候被析構
|
|
|
20 修改 刪除 舉報 引用 回覆 |
id="Topic_Zone" marginwidth="0" marginheight="0" frameborder="0" width="100%" scrolling="no" height="0">
-
- 加爲好友
- 發送私信
- 在線聊天
- skyell
- 等級:
- 可用分等級:
- 總技術分:
- 總技術分排名:
|
發表於:2007-09-21 17:35:5816樓 得分:0 | 高深,深入學習 |
|