[fpc-devel] Warning: Constructor should be public
Flávio Etrusco
flavio.etrusco at gmail.com
Mon Apr 6 23:51:02 CEST 2009
Actually, your constructor has the same signature as 'TObject.Create',
so it should show a 'lower visibility' warning in Delphi, doesn't it?
But, indeed, FPC shows the warning (should be public) for all
constructors, even if you're not hiding from the parent class, and I
always found this a (minor) annoyance.
But the fact that the semantic of constructors in Delphi/ObjectPascal
have the same visibility rules of "common methods" (i.e. they force
the visibility of the constructor from the parent class) is just sad.
"Even" Java constructors' syntax is better ;-)
Not to mention that you can call constructors on instance "pointer"
(ok, I know this "hack is useful/used in streaming/persistence code),
even uninitialized ones...
-Flávio
On Mon, Apr 6, 2009 at 5:37 PM, Léo Willian Kölln <leokolln at gmail.com> wrote:
> No.
> See my singleton example:
>
> TLoggerGeral = class
> private
> {$IFDEF WINDOWS}
> class var FInstance : TLoggerGeral;
> {$ELSE}
> {$STATIC on}
> FInstance : TLoggerGeral; static;
> {$ENDIF}
>
> constructor Create;
>
> protected
> pCritSection : TCriticalSection;
> pLogarDatas : boolean;
> pLogarTipos : boolean;
> pArquivoDestino : TextFile;
> saidaConsole : boolean;
>
> class function getData: String;
> class function tipoText(tipo: ETipoMensagem): String;
> class procedure executaOperacaoPrioridade(tipo: ETipoMensagem);
>
> public
> destructor Destroy; override;
> class function GetInstance: TLoggerGeral;
> class procedure recebeMensagem(const mensagem: String; tipo:
> ETipoMensagem = NORMAL);
> end;
>
> A normal singleton and it complain!
>
> Léo Willian Kölln
>
>
> On Mon, Apr 6, 2009 at 4:41 PM, Graeme Geldenhuys
> <graemeg.lists at gmail.com> wrote:
>>> Simply question. Why?
>>
>>
>> What did you do, try and lower the visibility of the constructor? If
>> so, that is also not allowed in Delphi as far as I know.
>>
>> Regards,
>> - Graeme -
>>
>>
>> _______________________________________________
>> fpGUI - a cross-platform Free Pascal GUI toolkit
>> http://opensoft.homeip.net/fpgui/
>> _______________________________________________
>> fpc-devel maillist - fpc-devel at lists.freepascal.org
>> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>
More information about the fpc-devel
mailing list