On 30 Oct 2013, at 15:00, Sven Barth wrote:

Am 30.10.2013 14:37, schrieb Jonas Maebe:

"Private" is just another way to define a scope, just like a unit interface and implementation define a scope. Neither the "private" section nor the interface of unit "u1" is in scope when the "hidden" type is used.
Using an interface uses as the analog for private types is flawed in my opinion. The analog code would more like this:

=== code begin ===

unit u2;

interface

function f: tdynarray;

implementation

type
 tdynarray = array of integer;

function f: tdynarray;
begin

end;

end.

=== code end ===

Which of course does not compile.

This is not equivalent. A private type declaration in a class adds a new identifier that is visible inside that class. You then use it, still in that class, to declare the return type of a function. Next, in a scope where that type identifier is no longer visible, you call the function.

My example is a complete match to that scenario as far as identifier visibility is concerned (you use a type in a scope where it is visible to declare a function return type, and then call the function in a scope where it is not visible). In your example, the type is not visible in the place where the function is declared but only where it is defined.


Jonas
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to