Addition of missing constructors

Top  Previous  Next

What is translated > Constructors > Addition of missing constructors

 

Unlike in Delphi, constructors of base classes cannot be called directly in C++. Additional constructor have to be defined in the derived class. Delphi2Cpp inserts missing constructors in C++ automatically. So, resuming the previous example, an additional standard constructor is created, which can be used with all classes, which are derived from TObject:

 

__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