建構函式中 this 的使用

2021-12-29 21:08:03 字數 411 閱讀 5937

:this(…)

•        乙個建構函式可以呼叫另一建構函式

struct colouredpoint

public colouredpoint(int x, int y, colour c)

...private int x, y;  www.2cto.com

private colour c;

}結構類總有一編譯器宣告的公有的預設建構函式。不管你有沒有宣告建構函式,編譯器宣告的公有的預設建構函式總是存在的。所以你不能定義預設建構函式,這樣會出現兩個預設建構函式,這是不允許的。但要注意的是,這只適合於結構,對於類是不適用的。使用者自定義的結構類的建構函式的預設訪問許可權是private,和結構類的字段一樣。

c#不允許你宣告乙個和建構函式名字一樣的函式。

作者:ershouyage

建構函式中 this 的使用

this 乙個建構函式可以呼叫另一建構函式 struct colouredpoint public colouredpoint int x,int y,colour c private int x,y private colour c 結構類總有一編譯器宣告的公有的預設建構函式。不管你有沒有宣告建構...

建構函式的使用

在c 中,我們一般會利用建構函式來初始化類裡面的成員函式,先看下面一段 可以自己先考慮輸出語句會不會是0?include using namespace std struct cls cls int main cls obj cout 在 第10行,不帶引數的建構函式直接呼叫了帶引數的建構函式。這種...

建構函式的使用

個人理解的建構函式的使用 function person name,height var person person xiaoli 180 var person1 person xiaohei 170 列印出來的結果是 person object person1 object 個人理解 functi...