Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-05

warning about hiding method in ancestor class

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Xiangrong Fang

Hello All,

I have a unit here:

https://github.com/xrfang/pastats/blob/master/src/units/datalist.pas

which report this error:

/home/xrfang/git/pastats/src/units/datalist.pas(61,17) Warning: An
inherited method is hidden by "constructor TDataFrame.Create;"

However, the following code, which also define a new constructor without using "overload", does NOT have such warning.

program Project1;
{$mode objfpc}{$H+}
type
  TBase = class
  public
    constructor Create(AName: string);
  end;
  TDerived = class(TBase)
  public
    constructor Create;
  end;
constructor TDerived.Create;
begin
  WriteLn('Creator of TDerived... anonymous');
end;
constructor TBase.Create(AName: string);
begin
  WriteLn('Creator of TBase: ', AName);
end;
var
  obj: TDerived;
begin
  obj := TDerived.Create;
end.

If I use reintroduce, I can suppress this warning. But my question is, why is this warning NOT displayed in the above sample code? In general, shall I use "reintroduce" keyword? Is it related to generics?

Thanks!

Xiangrong

Reply by email

Sven Barth
to Xiangrong Fang
Xiangrong Fang wrote 14 lines
Hello All, I have a unit here: https://github.com/xrfang/pastats/blob/master/src/units/datalist.pas which report this error: /home/xrfang/git/pastats/src/units/datalist.pas(61,17) Warning: An inherited method is hidden by "constructor TDataFrame.Create;" However, the following code, which also define a new constructor without using "overload", does NOT have such warning.

[snip]

If I use reintroduce, I can suppress this warning. But my question is, why is this warning NOT displayed in the above sample code? In general, shall I use "reintroduce" keyword? Is it related to generics?

If I remember correctly that warning appears if you have a non-virtual constructor with the same arguments as a virtual constructor of the base class. It should however not be related to generics in any way...

Regards,
Sven

Reply by email