Content deleted Content added
Merged .NET specific definition for "cctor" into C# section; added abbreviation and notice to copy ctor. |
Default constructors - correction for C++, clarification for other languages. |
||
Line 46:
If the programmer does not supply a constructor for an instantiable class, most languages will provide a ''[[default constructor]]''.
The behavior of the default constructor is language dependent. It may initialize data members to zero or other same values, or it may do nothing at all
Some languages (Java, C#, VB .NET) will default construct arrays of class types to contain null references. Languages without null references may not allow default construction of arrays of non default constructible objects, or require explicit initialization at the time of the creation (C++):
<source lang="cpp">
#include <iostream>
struct not_default_constructible {
not_default_constructible() = delete; // delete default constructor
not_default_constructible(int x) { std::cout << "Constructed with " << x << '\n'; }
};
int main() {
not_default_constructible static_array[] =
{ 1, 2, 3 };
not_default_constructible *dynamic_array =
new not_default_constructible[3]{ 4, 5, 6 }; // C++11
}
</source>
=== Copy constructors ===
|