Problems with constructors |
Top Previous Next |
What is translated > Types > Records, Classes, Interfaces > Class > Constructors > Problems with constructors
Summarizing, there remain two problems for which the translated constructors have to be checked:
There is still another problem with special constructors. In Delphi there can be several constructors with the same signature but with different names.. E.g.:
TCoordinate = class(TObject) public constructor CreateRectangular(AX, AY: Double); constructor CreatePolar(Radius, Angle: Double); private x,y : Double; end;
constructor TCoordinate.CreateRectangular(AX, AY: Double); begin x := AX; y := AY; end
constructor TCoordinate.CreatePolar(Radius, Angle: Double); begin x := Radius * cos(Angle); y := Radius * sIn(Angle); end
After translation the two constructors become ambiguous:
public class TCoordinate : TObject { public TCoordinate(double AX, double AY) { CreateRectangular(AX, AY); } public void CreateRectangular(double AX, double AY) { x = AX; y = AY; } public TCoordinate(double Radius, double Angle) { CreatePolar(Radius, Angle); } public void CreatePolar(double Radius, double Angle) { x = Radius * cos(Angle); y = Radius * sIn(Angle); } private double x; private double y;
public TCoordinate() {} };
In such cases the conflict has to be avoided manually. |
This page belongs to the Delphi2C# Documentation |
Delphi2C# home Content |