Next: , Previous: Pragma CPP_Class, Up: Implementation Defined Pragmas

Pragma CPP_Constructor


     pragma CPP_Constructor ([Entity =>] LOCAL_NAME);

This pragma identifies an imported function (imported in the usual way with pragma Import) as corresponding to a C++ constructor. The argument is a name that must have been previously mentioned in a pragma Import with Convention = CPP, and must be of one of the following forms:

where T is a tagged type to which the pragma CPP_Class applies.

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:

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.

Pragma CPP_Constructor is intended primarily for automatic generation using an automatic binding generator tool. See Interfacing to C++ for more related information.