[fpc-pascal] Compiler Warning: Constructor should be public

Anthony Walter sysrpl at gmail.com
Wed Nov 11 03:57:31 CET 2009


QFT, Flávio said:

"Graeme, I guess the OP didn't want to reintroduce the 'Create'
constructor with lower visibility, just implement a second constructor
(** with a different name **) with private visiblity. It can be useful
when implementing singletons and factories to avoid some types of
misuse by an unattentive coworker...

IIRC the last time this issue was raised you were on the side for
removing the warning - my opinion too ;-)"

Yes! And well put. *Thank you*

2009/11/10 Flávio Etrusco <flavio.etrusco at gmail.com>:
> On Tue, Nov 10, 2009 at 10:56 AM, Graeme Geldenhuys
> <graeme at mastermaths.co.za> wrote:
>> Anthony Walter wrote:
>>>
>>> In my opinion the warning should be removed, or at least able to be
>>> suppress through a switch. I beginning to make the transition to cross
>>
>> The compiler is 100% and I think it should actually raise an Error
>> instead of a Warning.
>>
>> Your code is flawed. Object Pascal is quite clear regarding visibility
>> rules. TObject has a Public constructor. You can only raise the
>> visibility from there, not reduce visibility.
>>
> (...)
>>
>>  raise EAssertError.Create;
>>
>> is perfectly legal, and will by-pass whatever you intended in your
>> CreateFromLine() constructor.
>>
>
> Graeme, I guess the OP didn't want to reintroduce the 'Create'
> constructor with lower visibility, just implement a second constructor
> with private visiblity.
> It can be useful when implementing singletons and factories to avoid
> some types of misuse by an unattentive coworker...
> IIRC the last time this issue was raised you were on the side for
> removing the warning - my opinion too ;-)
>
> -Flávio
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



More information about the fpc-pascal mailing list