Initializing arrays |
Top Previous Next |
What is translated > Types > Arrays > Initializing arrays
The initialization of arrays in Delphi and C++ looks very similar. For example the initialization of an array of TStyleRecord's:
TStyleRecord = record Name : string; Color : TColor; Style : TFontStyles; end; TStylesArray = array[0 .. 2] of TStyleRecord;
might be:
DefaultStyles : TStylesArray = ( (Name : 'tnone'; Color : clBlack; Style : []), (Name : 'tstring'; Color : clMaroon; Style : []), (Name : 'tcomment'; Color : clNavy; Style : [fsItalic]) );
With the C++11 std::initializer_list there is a simple equivalent in C++:
#define arrayinit__0 TSet<int, 0, 255>() #define arrayinit__1 TSet<int, 0, 255>() #define arrayinit__2 (TSet<int, 0, 255>() << fsItalic)
const TStylesArray DefaultStyles = {{_T("tnone"), clBlack, arrayinit__0}, {_T("tstring"), clMaroon, arrayinit__1}, {_T("tcomment"), clNavy, arrayinit__2}};
In C++98 this was not possible, because all elements in such lists had to be C built in types.
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |