17.10.1 Constructor initializers

来源:互联网 发布:php的curl选项curlopt 编辑:程序博客网 时间:2024/06/15 19:07
All instance constructors (except those for class object) implicitly include
an invocation of another instance
constructor immediately before the constructor-body. The constructor to
implicitly invoke is determined by the
constructor-initializer:
? An instance constructor initializer of the form base(argument-listopt)
causes an instance constructor from
the direct base class to be invoked. That constructor is selected using
argument-list and the overload
resolution rules of §14.4.2. The set of candidate instance constructors
consists of all accessible instance
constructors declared in the direct base class, or the default constructor (
§17.10.4), if no instance constructors
are declared in the direct base class. If this set is empty, or if a single
best instance constructor cannot be
identified, a compile-time error occurs.
? An instance constructor initializer of the form this(argument-listopt)
causes an instance constructor from
the class itself to be invoked. The constructor is selected using
argument-list and the overload resolution rules
of §14.4.2. The set of candidate instance constructors consists of all
accessible instance constructors declared
in the class itself. If that set is empty, or if a single best instance
constructor cannot be identified, a compiletime
error occurs. If an instance constructor declaration includes a constructor
initializer that invokes the
constructor itself, a compile-time error occurs.
If an instance constructor has no constructor initializer, a constructor
initializer of the form base() is implicitly
provided. [Note: Thus, an instance constructor declaration of the form
C(?) {?}
is exactly equivalent to
C(?): base() {?}
end note]
The scope of the parameters given by the formal-parameter-list of an
instance constructor declaration includes
the constructor initializer of that declaration. Thus, a constructor
initializer is permitted to access the parameters
of the constructor. [Example: For example:
class A
{
public A(int x, int y) {}
}
class B: A
{
public B(int x, int y): base(x + y, x - y) {}
}
end example]
An instance constructor initializer cannot access the instance being
created. Therefore it is a compile-time error to
reference this in an argument expression of the constructor initializer, as
it is a compile-time error for an
argument expression to reference any instance member through a simple-name.
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 入住淘宝主播没有微博粉丝怎么办 手机淘宝领金币怎么没有了怎么办 淘宝荬家缺货对付款买家怎么办 淘宝买家确认收货后申请退款怎么办 淘宝东西失效了但付过款了怎么办 淘宝图片被投诉盗图怎么办原图没了 淘宝退款申请不小心撤销了怎么办 淘宝不小心点了撤销退款怎么办 淘宝上退款不小心撤销了怎么办 新店淘宝卖家想开通直播怎么办 想开通淘宝直播却没有粉丝怎么办 淘宝店家拒绝给我改地址怎么办0 淘宝被投诉卖假申诉失败怎么办 要退保证金但是有人买东西了怎么办 手机淘宝上我是商家停止服务怎么办 淘宝上买的电脑商家关闭了怎么办 淘宝链接复制链链接发不出去怎么办 淘宝卖家填错地址货已经发了怎么办 拼多多没交保证金无法提现怎么办 信用卡被别人刷了没证据怎么办 我在淘宝开个店卖衣服没人买怎么办 收货地址填错了卖家已发货怎么办 淘宝店上的供货商不发货怎么办 在淘宝买的花退到卖家后死了怎么办 在淘宝买东西付款开通了花呗怎么办 淘宝网投诉卖家也不处理问题怎么办 淘宝图片空间上传不了大图片怎么办 不小心把设置里打印机删掉了怎么办 电脑上qq不小心删掉了怎么办 进了一批款式不好卖的衣服怎么办? 淘宝首页图片不居中代码装的怎么办 小语言代码装修以后不是全屏怎么办 招教年龄超过4个月怎么办 淘宝上注册的店铺被别人用了怎么办 淘宝贷款后店铺转让了贷款怎么办 手机千牛发布宝贝类目找不到怎么办 亚马逊被移除销售权该怎么办 玉米煮水不够熟吃了怎么办 华为云手机找回关了找回手机怎么办 我的淘宝号被别人盗用开店怎么办 淘宝买东西发货了不想要了怎么办