Revision history for ProPgCtorsDtors


Revision [21471]

Last edited on 2016-05-14 01:52:16 by fxm [Updated one detail]
Additions:
Simply, constructors are special member procedures that are called when an object is created, and destructors are special member procedures called when an object is destroyed. Both constructors and destructors are called automatically by the compiler whenever an object is created or destroyed, whether explicitly with the use of the ##[[KeyPgDim|Dim]]## or ##[[KeyPgOpNew|New]]##/##[[KeyPgOpDelete|Delete]]## keywords, or implicitly by passing an object to a procedure by value or through an object going out of scope.
Deletions:
Simply, constructors are special member procedures that are called when an object is created, and destructors are special member procedures called when an object is destroyed. Both constructors and destructors are called automatically by the compiler whenever an object is created or destroyed, whether explicitly with the use of the ##[[KeyPgDim|Dim]]## or ##[[KeyPgOpNew|New]]## keywords, or implicitly by passing an object to a procedure by value or through an object going out of scope.


Revision [21207]

Edited on 2016-03-13 12:38:07 by fxm [Formatting]
Additions:








Revision [20632]

Edited on 2016-02-10 16:12:40 by DkLwikki [Update link format]
Additions:
Simply, constructors are special member procedures that are called when an object is created, and destructors are special member procedures called when an object is destroyed. Both constructors and destructors are called automatically by the compiler whenever an object is created or destroyed, whether explicitly with the use of the ##[[KeyPgDim|Dim]]## or ##[[KeyPgOpNew|New]]## keywords, or implicitly by passing an object to a procedure by value or through an object going out of scope.
Constructors and destructors are declared like member procedures but with the ##[[KeyPgConstructor|Constructor]]## keyword instead of ##[[KeyPgMemberSub|Sub]]## or ##[[KeyPgMemberFunction|Function]]##, and without a name. Similarly, they are defined with only the name of the ##[[KeyPgType|Type]]## or ##[[KeyPgClass|Class]]## they are declared in.
A ##[[KeyPgType|Type]]## or ##[[KeyPgClass|Class]]## can have multiple constructors, but only one destructor.
Default constructors are constructors that either have no parameters, or all of their parameters have a default value. They are called when an object is defined but not initialized, or is created as part of an array, with the ##[[KeyPgDim|Dim]]##, ##[[KeyPgRedim|Redim]]## or ##[[KeyPgOpNew|New]]##[] keywords. The first constructor declared in the example below is a default constructor.
Copy constructors are only called when creating and initializing object instances. Assignment to objects is handled by the ##[[KeyPgOperator|member operator let]]##.
Unlike other member procedures, constructors are generally not called directly from an object instance. Instead, a constructor is specified in a ##[[KeyPgDim|Dim]]## statement either with an initializer or without one, or in a ##[[KeyPgOpNew|New]]## statement with or without arguments.
If no copy constructor is declared for a ##[[KeyPgType|Type]]## or ##[[KeyPgClass|Class]]##, the compiler provides one. If no constructor has been declared, the compiler also provides a default constructor.
Deletions:
Simply, constructors are special member procedures that are called when an object is created, and destructors are special member procedures called when an object is destroyed. Both constructors and destructors are called automatically by the compiler whenever an object is created or destroyed, whether explicitly with the use of the ##[[KeyPgDim Dim]]## or ##[[KeyPgOpNew New]]## keywords, or implicitly by passing an object to a procedure by value or through an object going out of scope.
Constructors and destructors are declared like member procedures but with the ##[[KeyPgConstructor Constructor]]## keyword instead of ##[[KeyPgMemberSub Sub]]## or ##[[KeyPgMemberFunction Function]]##, and without a name. Similarly, they are defined with only the name of the ##[[KeyPgType Type]]## or ##[[KeyPgClass Class]]## they are declared in.
A ##[[KeyPgType Type]]## or ##[[KeyPgClass Class]]## can have multiple constructors, but only one destructor.
Default constructors are constructors that either have no parameters, or all of their parameters have a default value. They are called when an object is defined but not initialized, or is created as part of an array, with the ##[[KeyPgDim Dim]]##, ##[[KeyPgRedim Redim]]## or ##[[KeyPgOpNew New]]##[] keywords. The first constructor declared in the example below is a default constructor.
Copy constructors are only called when creating and initializing object instances. Assignment to objects is handled by the ##[[KeyPgOperator member operator let]]##.
Unlike other member procedures, constructors are generally not called directly from an object instance. Instead, a constructor is specified in a ##[[KeyPgDim Dim]]## statement either with an initializer or without one, or in a ##[[KeyPgOpNew New]]## statement with or without arguments.
If no copy constructor is declared for a ##[[KeyPgType Type]]## or ##[[KeyPgClass Class]]##, the compiler provides one. If no constructor has been declared, the compiler also provides a default constructor.


Revision [16249]

Edited on 2012-08-11 19:20:43 by CountingPine [it's -> its]
Additions:
The compiler-provided default constructor initializes member data to default values, that is, numeric and pointer members are set to zero (0), and object members are default-constructed. The copy constructor that the compiler declares shallow-copies all member data from one type to another: numeric and pointer types are initialized with the corresponding data members in the object that is copied, and object members are copy-constructed from their corresponding object members. This means that dynamic resources, such as memory pointed to by a pointer data member, is not copied; only the address is copied. So if an object owns a resource, meaning it is responsible for its creation and destruction, then the compiler-generated copy constructor will not be sufficient.
Deletions:
The compiler-provided default constructor initializes member data to default values, that is, numeric and pointer members are set to zero (0), and object members are default-constructed. The copy constructor that the compiler declares shallow-copies all member data from one type to another: numeric and pointer types are initialized with the corresponding data members in the object that is copied, and object members are copy-constructed from their corresponding object members. This means that dynamic resources, such as memory pointed to by a pointer data member, is not copied; only the address is copied. So if an object owns a resource, meaning it is responsible for it's creation and destruction, then the compiler-generated copy constructor will not be sufficient.


Revision [15585]

Edited on 2011-12-29 04:48:55 by FxMwikki [Fixed ambiguous phrase in ยง 'Calling constructors'.]
Additions:
Unlike other member procedures, constructors are generally not called directly from an object instance. Instead, a constructor is specified in a ##[[KeyPgDim Dim]]## statement either with an initializer or without one, or in a ##[[KeyPgOpNew New]]## statement with or without arguments.
Deletions:
Unlike other member procedures, constructors can to be not called directly from an object instance. Instead, a constructor is specified in a ##[[KeyPgDim Dim]]## statement either with an initializer or without one, or in a ##[[KeyPgOpNew New]]## statement with or without arguments.


Revision [15584]

Edited on 2011-12-29 00:15:20 by FxMwikki [Fixed ambiguous phrase in 'Calling constructors'.]
Additions:
Unlike other member procedures, constructors can to be not called directly from an object instance. Instead, a constructor is specified in a ##[[KeyPgDim Dim]]## statement either with an initializer or without one, or in a ##[[KeyPgOpNew New]]## statement with or without arguments.
Deletions:
Unlike other member procedures, constructors cannot be called directly from an object instance. Instead, a constructor is specified in a ##[[KeyPgDim Dim]]## statement either with an initializer or without one, or in a ##[[KeyPgOpNew New]]## statement with or without arguments.


Revision [11953]

The oldest known version of this page was created on 2007-12-21 15:02:10 by ElSairon [Fixed ambiguous phrase in 'Calling constructors'.]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode