一道题关于构造析构的顺序

#include<iostream>
#include<stdlib.h>

/*
因为t1,t6是全局变量,t4,t5是在外部函数中局部变量,所以构造函数调用完之后就是析构函数
t1,t6,t2,t3 
 t4,~t4,t5,~t5, 
  ~t3,~t2,~t6,~t1

*/

using namespace std;
class Test
{
	int m_data;
	public:
	Test(int i):m_data(i)
	{
		cout<<"Test()  m_data="<<m_data<<endl;
	}

	~Test(){
		cout<<"~Test() m_data="<<m_data<<endl;
	}

};


Test t1(10);
void func() {
	Test t4(40);
}
void show() {
   static  Test t5(50);
}
int main()
{
	Test t2(20);
	Test t3(30);
	func();
	show();
}
Test t6(60);

posted @ 2015-11-07 19:12  cloudren2020  阅读(63)  评论(0编辑  收藏  举报