Constructor of the base class |
Top Previous Next |
What is translated > Types > Records, Classes, Interfaces > Class > Constructors > Constructor of the base class
In Delphi and C++ the order of construction of the derived and the base classes is differently. In Delphi the derived class is constructed first, while in C++ the constructors of the base classes are executed automatically, before the constructor of the derived class is executed. If the base class has no standard constructor (= constructor without parameters) the base class constructor has to be called in the initialization list with the according parameters.The constructors of the ancestor classes are executed in Delphi only, if they are called explicitly from in the written code. In such cases Delphi2Cpp tries to find this call and puts it into the initialization list:
constructor foo.Create(Owner: TComponent); begin inherited Create(Owner); end;
->
__fastcall foo::foo ( TComponent * Owner ) : inherited ( Owner ) { }
There is a second reason, why this shift is necessary: in C++ the explicit call of an ancestor constructor in the derived constructor has no effect. (A temporary instance of the base class will be created only.)
Base class constructors without parameters are called automatically in C++. Delphi2Cpp preserves the original calls of such constructors as line comments.
constructor foo.Create(); begin inherited Create; end;
->
__fastcall foo::foo ( ) { // inherited::Create; }
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |