我用下面的程序简单测试了一下全局对象,它在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 修改 删除 举报 引用 回复 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|