W1029 Duplicate %s '%s' with identical parameters will be inacessible from C++ (Object Pascal)

From Appmethod Topics
Jump to: navigation, search

Go Up to Error and Warning Messages (Object Pascal) Index

An object file is being generated and Two, differently named, constructors or destructors with identical parameter lists have been created; they will be inaccessible if the code is translated to an HPP file because constructor and destructor names are converted to the class name. In C++ these duplicate declarations will appear to be the same function.


unit Produce;
interface
  type
    Base = class
      constructor ctor0(a, b, c : integer);
      constructor ctor1(a, b, c : integer);
    end;

implementation
constructor Base.ctor0(a, b, c : integer);
begin
end;

constructor Base.ctor1(a, b, c : integer);
begin
end;

begin
end.


As can be seen in this example, the two constructors have the same signature and thus, when the file is compiled with one of the -j options, will produce this warning.


unit Solve;
interface
  type
    Base = class
      constructor ctor0(a, b, c : integer);
      constructor ctor1(a, b, c : integer; dummy : integer = 0);
    end;

implementation
constructor Base.ctor0(a, b, c : integer);
begin
end;

constructor Base.ctor1(a, b, c : integer; dummy : integer);
begin
end;

begin
end.


A simple method to solve this problem is to change the signature of one of constructors, for example, to add an extra parameter. In the example above, a default parameter has been added to ctor1. This method of approaching this error has the benefit that Object Pascal code using ctor1 does not need to be changed. C++ code, on the other hand, will have to specify the extra parameter to allow the compiler to determine which constructor is desired.