Addition of missing constructors

Top  Previous  Next

What is translated > Types > Records, Classes, Interfaces > Class > Constructors > Addition of missing constructors

 

Unlike in Delphi, constructors of base classes cannot be called directly in C++. If there are public constructors in the base classes with different signatures as any constructor of the derived class, these constructors are generated for the derived class too. Especially in Delphi all classes are derived from TObject and inherit its default constructor. Therefore Delphi2Cpp generates a default constructor for each derived class, even if such a constructor doesn't exist in the original Delphi code. So, resuming the previous example, the additional standard constructor would look like:

 

__fastcall Base::Base()

 : FI(0),

   FList(NULL),

   FTimeOut(0)

{

}

 

Here the member variables are initialized with default values.

 

Sometimes a lot of additional code has to be produced for C++ classes. For example a class, which is derived from Exception has more than ten constructors. Inside of each constructor the constructor of the base class has to be called in the initialization list

 

 

class MyException: public Sysutils::Exception {

  typedef Sysutils::Exception inherited;

  public: inline __fastcall MyException( const String MSG ) : inherited( MSG ) {}

  public: inline __fastcall MyException( const String MSG, const TVarRec* Args, int Args_maxidx ) : inherited( MSG, Args, Args_maxidx ) {}

  public: inline __fastcall MyException( int Ident ) : inherited( Ident ) {}

  public: inline __fastcall MyException( PResStringRec ResStringRec ) : inherited( ResStringRec ) {}

  public: inline __fastcall MyException( int Ident, const TVarRec* Args, int Args_maxidx ) : inherited( Ident, Args, Args_maxidx ) {}

  public: inline __fastcall MyException( PResStringRec ResStringRec, const TVarRec* Args, int Args_maxidx ) : inherited( ResStringRec, Args, Args_maxidx ) {}

  public: inline __fastcall MyException( const String MSG, int AHelpContext ) : inherited( MSG, AHelpContext ) {}

  public: inline __fastcall MyException( const String MSG, const TVarRec* Args, int Args_maxidx, int AHelpContext ) : inherited( MSG, Args, Args_maxidx, AHelpContext ) {}

  public: inline __fastcall MyException( int Ident, int AHelpContext ) : inherited( Ident, AHelpContext ) {}

  public: inline __fastcall MyException( PResStringRec ResStringRec, int AHelpContext ) : inherited( ResStringRec, AHelpContext ) {}

  public: inline __fastcall MyException( PResStringRec ResStringRec, const TVarRec* Args, int Args_maxidx, int AHelpContext ) : inherited( ResStringRec, Args, Args_maxidx, AHelpContext ) {}

  public: inline __fastcall MyException( int Ident, const TVarRec* Args, int Args_maxidx, int AHelpContext ) : inherited( Ident, Args, Args_maxidx, AHelpContext ) {}

};

 

 

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content