[fpc-devel] protected members access across classes in the same package, but what about inherited cross package
Joao Morais
post at joaomorais.com.br
Sun Jul 20 19:25:06 CEST 2008
Martin Friebe wrote:
> [file foo.pp]
> type
> TThat = class(TObject)
> protected
> ThatValue : integer
> end;
>
> TThis = class(TObject)
> ....
> end;
> implementation ...
> [/end of file foo.pp]
>
> [file bar.pp]
> type
> TThatFake class(TThat)
> end; // intntionally empty class
>
> TSomething = class(...)
> ....
> [/end of file bar.pp]]
>
> - If TThatFake had any code, then any code belonging to TThatFake would
> be allowed to see it's anchestor protected members, that would be correct.
Yes. Inheritance.
> - If TThatFake had any protected mebers implemented in bar.pp they
> should be visble to other code in bar.pp
Yes. Friend classes.
> - But what about inherited members? Should TSomething be able to access
> ThatValue?
Yes, if the object pointer is declared as TThatFake or you cast the
pointer to TThatFake. Otherwise no, only public members of TThat would
be visible.
Joao Morais
More information about the fpc-devel
mailing list