At the end of the declarations cited period, and will not call the destructor, only the end of the statement cycle body, it will call the destructor

example

 1 class Test
 2 {
 3 public:
 4     Test() { cout << "construct" << endl; }
 5     ~Test() { cout << "destruct" << endl; }
 6 };
 7 
 8 int main()
 9 {
10     Test t1;
11     {
12         Test& t2 = t1;
13     }
14     cout << "............................." << endl;
15     return 0;
16 }

result:

 

Guess you like

Origin www.cnblogs.com/XiaoXiaoShuai-/p/11608595.html