Can you publicly alias a private type?

Nick Sabalausky a at a.a
Wed Jun 22 13:47:55 PDT 2011


"Peter Alexander" <peter.alexander.au at gmail.com> wrote in message 
news:itsqov$1mnt$1 at digitalmars.com...
> On 22/06/11 2:19 PM, Nick Sabalausky wrote:
>> In your example, the user needs to be able to use the Foo symbol in order 
>> to
>> get full use out of Foos. However, in my example, the user does *not* 
>> need
>> to use the Foo symbol in order to get full use out of Bar. They can just 
>> use
>> Bar in place of Foo. The "Foo" symbol is a necessary part of Foos's
>> interface, but it is *not* a necessary part Bar's interface.
>
> They don't *need* the Foo symbol:
>
> // module A
> private class Foo;
> public alias Foo[] Foos;
> Foos getFoos();
>
> // module B
> import A;
> void main()
> {
>     Foos foos = getFoos();
>     foos[0].someFunc();
>     auto f = foos[0];
> }
>
>
> Here, module B hasn't used the Foo symbol, but it's as if Foo isn't 
> private at all. I don't know about you, but this feel really wrong to me.
>

Perhaps. I could probably be persuaded either way.

But again, I don't see that as being relevent to:

private class Foo;
public alias Foo Bar;





More information about the Digitalmars-d mailing list