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.

OOPS Corner : Instance Constructors

In this section we will see about instance constructors.Instance ConstructorsInstance constructors a...
  • waterboy
  • waterboy
  • 2004年09月19日 09:52
  • 632

8.7.8 Instance constructors

An instance constructor is a member that implements the actions required to initialize an instance o...
  • masterall
  • masterall
  • 2005年11月30日 19:12
  • 580

Avoid non-default constructors in fragments

在使用Android Studio时Fragment类报 Avoid non-default constructors in fragments
  • yyqasg
  • yyqasg
  • 2014年11月13日 12:38
  • 2269

Autofuc None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructor

最近项目中使用Autofuc实现依赖注入时出现错误: None of the constructors found with 'Autofac.Core.Activators.Reflectio...
  • shenwenbin0106
  • shenwenbin0106
  • 2017年03月17日 16:02
  • 1339

Avoid non-default constructors in fragments的解决方法

今天在使用Android Studio打包的时候遇到了一个错误,错误的提示信息是这样子的:“Avoid non-default constructors in fragments: use a def...
  • runningampH
  • runningampH
  • 2016年04月06日 14:20
  • 3085

error C2533: ' ::{ctor}' : constructors not allowed a return type

error C2533: ' ::{ctor}' : constructors not allowed a return type 出现这个错误是因为在定义的类体中,在最后少了个分号“;...
  • andkobe
  • andkobe
  • 2011年02月13日 15:07
  • 4726

Fragment:关于Avoid non-default constructors in fragments的错误

关于Avoid non-default constructors in fragments的错误
  • MaximusKiang
  • MaximusKiang
  • 2014年06月19日 10:30
  • 3014

C++:类的语法错误 error c2533:constructors not allowed a return type(构造函数不允许返回一个类型)

C++:类的语法错误  errorc 2533:constructors not allowed a return type(构造函数不允许返回一个类型)...
  • sky_will
  • sky_will
  • 2016年04月10日 09:44
  • 1684

Android Fragment avoid non-default constructors in fragments use a default constructor plus fragment

一、出现情况。 新建Fragment并重新构造函数传递参数的时候。 二、出现原因。 当Fragment被销毁,在重建的时候,系统只会调用默认的无参构造函数,这样我们自己定义的参数就有可能不能正确初...
  • wblyuyang
  • wblyuyang
  • 2016年01月18日 15:37
  • 972

C++三种class constructors

class A { public: A(int a) : a_(a) {} A(const A &a) : a_(a.a_) {} A &operator=(con...
  • u013034520
  • u013034520
  • 2017年11月03日 06:23
  • 101
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:17.10 Instance constructors
举报原因:
原因补充:

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