久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

是否在初始化變量之前調(diào)用了父類構(gòu)造函數(shù)?

Are parent class constructors called before initializing variables?(是否在初始化變量之前調(diào)用了父類構(gòu)造函數(shù)?)
本文介紹了是否在初始化變量之前調(diào)用了父類構(gòu)造函數(shù)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

是在初始化變量之前調(diào)用父類的構(gòu)造函數(shù),還是編譯器會先初始化類的變量?

Are parent class constructors called before initializing variables, or will the compiler initialize the variables of the class first?

例如:

class parent {
  int a;
public:
  parent() : a(123) {};
};

class child : public parent {
  int b;
public:
            // question: is parent constructor done before init b?
  child() : b(456), parent() {};
}

推薦答案

是的,基類在派生類成員和構(gòu)造函數(shù)體執(zhí)行之前初始化.

Yes, the base class is initialized before the members of the derived class and before the constructor body executes.

在非委托構(gòu)造函數(shù)中,初始化在以下順序:

In a non-delegating constructor, initialization proceeds in the following order:

——首先,并且只針對大多數(shù)的構(gòu)造函數(shù)派生類(1.8),虛基類按順序初始化它們出現(xiàn)在有向的從左到右的深度優(yōu)先遍歷中基類的非循環(huán)圖,其中從左到右"是派生類中基類的外觀基本說明符列表.

— First, and only for the constructor of the most derived class (1.8), virtual base classes are initialized in the order they appear on a depth-first left-to-right traversal of the directed acyclic graph of base classes, where "left-to-right" is the order of appearance of the base classes in the derived class base-specifier-list.

——然后??,直接基類在出現(xiàn)在基本說明符列表中的聲明順序(不管內(nèi)存初始化器的順序如何).

— Then, direct base classes are initialized in declaration order as they appear in the base-specifier-list (regardless of the order of the mem-initializers).

——然后??,非靜態(tài)數(shù)據(jù)成員按照它們在類定義(同樣不管內(nèi)存初始化器).

— Then, non-static data members are initialized in the order they were declared in the class definition (again regardless of the order of the mem-initializers).

——最后,復(fù)合語句構(gòu)造函數(shù)體被執(zhí)行.

— Finally, the compound-statement of the constructor body is executed.

這篇關(guān)于是否在初始化變量之前調(diào)用了父類構(gòu)造函數(shù)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 成人福利网站 | 七七婷婷婷婷精品国产 | 亚洲电影免费 | 91中文字幕 | 久久成人精品 | 欧美国产视频 | 亚洲三区在线播放 | 欧美日韩久久精品 | 欧美日一区二区 | av免费入口 | 国产视频精品区 | 午夜二区 | 天天干天天爱天天爽 | 国产美女在线播放 | 国产一二区在线 | 亚洲视频欧美视频 | 欧美日韩国产精品一区 | 日本精品在线一区 | 午夜视频一区 | 黄一区二区三区 | 亚洲播放一区 | 一区中文 | 9191成人精品久久 | 精品国产一级片 | 国产在线aa| 国产精品久久久久久久久久久久 | 国产精品伦一区二区三级视频 | 欧美日韩久久精品 | 日韩欧美中文字幕在线观看 | 日本a视频 | 日韩视频精品在线 | 欧美在线a| 日韩欧美在线观看一区 | 国产精品久久久久一区二区三区 | 欧美成人h版在线观看 | 久久久久久www | 国产黄色麻豆视频 | 99久久精品免费看国产小宝寻花 | 亚洲九色| 男人天堂av网站 | 久久伊人一区二区 |