17.10 Instance constructors

原创 2006年05月21日 02:50:00
An instance constructor is a member that implements the actions required to
initialize an instance of a class.
Instance constructors are declared using constructor-declarations:
constructor-declaration:
attributesopt constructor-modifiersopt constructor-declarator
constructor-body
constructor-modifiers:
constructor-modifier
constructor-modifiers constructor-modifier
constructor-modifier:
public
protected
internal
private
extern
constructor-declarator:
identifier ( formal-parameter-listopt ) constructor-initializeropt
constructor-initializer:
: base ( argument-listopt )
: this ( argument-listopt )
constructor-body:
block
;
A constructor-declaration may include a set of attributes (§24), a valid
combination of the four access modifiers
(§17.2.3), and an extern (§17.5.7) modifier. A constructor declaration is
not permitted to include the same
modifier multiple times.
The identifier of a constructor-declarator must name the class in which the
instance constructor is declared. If
any other name is specified, a compile-time error occurs.
The optional formal-parameter-list of an instance constructor is subject to
the same rules as the formalparameter-
list of a method (§17.5). The formal parameter list defines the signature (
§10.6) of an instance
constructor and governs the process whereby overload resolution (§14.4.2)
selects a particular instance
constructor in an invocation.
Each of the types referenced in the formal-parameter-list of an instance
constructor must be at least as accessible
as the constructor itself (§10.5.4).
The optional constructor-initializer specifies another instance constructor
to invoke before executing the
statements given in the constructor-body of this instance constructor. This
is described further in §17.10.1.
When a constructor declaration includes an extern modifier, the constructor
is said to be an external
constructor.
Because an external constructor declaration provides no actual
implementation, its constructor-body consists of a
semicolon. For all other constructors, the constructor-body consists of a
block, which specifies the statements to
initialize a new instance of the class. This corresponds exactly to the
block of an instance method with a void
return type (§17.5.8).
Instance constructors are not inherited. Thus, a class has no instance
constructors other than those actually
declared in the class. If a class contains no instance constructor
declarations, a default instance constructor is
automatically provided (§17.10.4).
Instance constructors are invoked by object-creation-expressions (§14.5.10.1
) and through constructorinitializers.

相关文章推荐

Thinking in Java 第17章 容器深入研究(17.10-17.14)

//声明:部分内容引自《Java编程思想(第四版)》机械工业出版社【连接接口的不同实现】– Hashtable、Vector、Stack 的“特征”是,它们是过去遗留下来的类,目的只是为了支持老的程序...
  • jia1410
  • jia1410
  • 2016年07月22日 08:58
  • 314

最新版Ubuntu 17.10与Windows双系统安装、配置与美化教程(转载)

感谢原创,原文地址 http://www.jianshu.com/p/62d947731401   [TOC] 本教程基于Ubuntu 17.10,但是除了下面的Gnome插件部分,同时也支持Ub...

终于下手,Ubuntu 17.10 用 GDM 取代 LightDM

在最近的一份报告中,Canonical 的 Will Cooke 透露,Ubuntu Desktop 团队正在考虑在即将推出的 Ubuntu 17.10 版本中以 GDM(GNOME显示管理器)取代 ...

C++构造函数语意学 - Constructor(The Semantics of Constructors)

1.默认构造函数(Default Constructor)default constructors 在编译器需要时被合成出来。被合成出来的constructor只执行编译器所需的行动。也就是说defa...

Constructors and Destructors in C++

原文地址:http://www.cprogramming.com/tutorial/constructor_destructor_ordering.html Constructors and Des...

《Effective_Java》 Item1:Consider static actor methods instead of constructors

使用静态工厂的优势 1.  不同于构造函数,可以赋予静态工厂更有意义的名字         eg. BigInteger的构造方法BigInteger(int, int, Random)返回一个可...
  • llsit
  • llsit
  • 2011年10月12日 23:01
  • 345

Copy constructors, assignment operators, and exception safe assignment

What is a copy constructor? A copy constructor is a special constructor for a class/struct that is u...

基本语言细节--《深度探索C++对象模型》--(2)The Semantics of Constructors--总结点

主要是针对Lippmen 书中C++中构造函数以及复制构造函数的论述做一个大致总结,以期说明编译器在C++语言背后为我们做了哪些事情!...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:17.10 Instance constructors
举报原因:
原因补充:

(最多只允许输入30个字)