[英]what does this type of declaration mean in c++?
我無法理解這一點; 請描述一下。 這是 C++ 代碼:
int upper(0), lower(0);
正如@dxiv 的評論中所指出的,這是對上變量和下變量的直接初始化。 以下語法也是直接初始化:
int even_lower{0};
當應用於非類類型對象時。 當應用於 class 類型的對象時,它會調用相關的構造函數或轉換運算符。
我將嘗試添加所有可能的方法來在這里分配變量
1
int upper=0, lower=0;
will assign upper as 0 and lower as 0
2 用單值初始化構造函數
int upper(0), lower(0);
will assign upper as 0 and lower as 0
3 帶多個值的構造函數初始化會用最后一個值初始化一個變量
int upper=(0,1,2,3), lower=(44,55,6,77,-5);
will assign upper as 3 and lower as -5
4 統一初始化只需要一個值,這里不能有多個值
int upper{0}, lower{0};
will assign upper as 0 and lower as 0
5 你可以在構造函數和單一值的統一初始化中使用 =
int upper={0}, lower={0};
will assign upper as 0 and lower as 0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.