?? static objects 的構(gòu)造和析構(gòu)順序.txt
字號:
* 1.本程序?qū)趖hinking in c++ p409 的“static object destructors ”。
* 2.本程序在與說明全局的static object 和 局部于函數(shù)的 static object的構(gòu)造和析構(gòu)順序
*3.記住書上說:P411。In c++, the constructor for a global static object is called before
* main() is entered, and destroyed as main() exits.
*4. the constructor of a local static object is called only if the function that includes its definition
* is called(如 f1() 中的 對象x1,也就是說如果f1()沒有被調(diào)用則對象x1不會被創(chuàng)建);
*5.p409 like ordinary destructors ,destruction of static objects occurs in the reverse order of initialization.
*/
#include<iostream>
using namespace std;
class X
{
public:
X( int ii = 0 ) : m_i( ii ) { cout << "構(gòu)造對象:x" << m_i << endl; }
~X(){ cout << "析構(gòu)對象x" << m_i << endl; }
private:
int m_i;
};
void f()
{
static X x1( 1 );
}
X x2( 2 ); // global ( static storage )!
X x3( 3 ); // global ( static storage )!
int main()
{
cout << "welcome to main() " << endl;
f();
cout<< "exiting main()" << endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -