pragma CPP_Constructor ([Entity =>] LOCAL_NAME [, [External_Name =>] static_string_EXPRESSION ] [, [Link_Name =>] static_string_EXPRESSION ]);
This pragma identifies an imported function (imported in the usual way
Import) as corresponding to a C++ constructor. If
Link_Name are not specified then the
Entity argument is a name that must have been previously mentioned
in a pragma
CPP. Such name
must be of one of the following forms:
where T is a tagged type to which the pragma
The first form is the default constructor, used when an object of type T is created on the Ada side with no explicit constructor. Other constructors (including the copy constructor, which is simply a special case of the second form in which the one and only argument is of type T), can only appear in two contexts:
Although the constructor is described as a function that returns a value on the Ada side, it is typically a procedure with an extra implicit argument (the object being initialized) at the implementation level. GNAT issues the appropriate call, whatever it is, to get the object properly initialized.
In the case of derived objects, you may use one of two possible forms for declaring and creating an object:
New_Object : Derived_T
New_Object : Derived_T := (constructor-call with
In the first case the default constructor is called and extension fields if any are initialized according to the default initialization expressions in the Ada declaration. In the second case, the given constructor is called and the extension aggregate indicates the explicit values of the extension fields.
If no constructors are imported, it is impossible to create any objects on the Ada side. If no default constructor is imported, only the initialization forms using an explicit call to a constructor are permitted.
CPP_Constructor is intended primarily for automatic generation
using an automatic binding generator tool.
See Interfacing to C++ for more related information.