Hiding types

Philippe Sigaud via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 30 13:09:59 PDT 2014


On Friday, 30 May 2014 at 20:02:40 UTC, Steven Schveighoffer 
wrote:

> If you want an opaque struct, you need to return it by pointer.

What do you mean? Like this?

Hidden* foo() { return new Hidden();}

?

> Otherwise, the user must be able to know what type it is 
> (otherwise, how would he use it?)

I just fear that by using internal, public, functions, the user 
might get access to a private type. I guess the D answer to that 
is to make foo private also. That makes sense.

I now realize that I implicitly considered 'private' to be 
transitive (or viral). That is that:

Hidden foo() { return Hidden();}

as foo is returning a value from a private type, it should be 
considered private also. By the compiler, I mean.


More information about the Digitalmars-d-learn mailing list