This section describes initialization using special member functions. It expands on the following discussions of initialization:
The default method of initialization is to perform a bit-for-bit copy from the initializer into the object to be initialized. This technique is applicable only to:
int i = 100;
int i;
int *pi = &i;
String sFileName( "FILE.DAT" );
String &rs = sFileName;
struct Point
{
int x, y;
};
Point pt = { 10, 20 }; // Static storage class only
Classes can specify more refined initialization by defining constructor functions. (For more information about declaring such functions, see Constructors.) If an object is of a class type that has a constructor, the object must be initialized, or there must be a default constructor. Objects that are not specifically initialized invoke the class’s default constructor.