Accessing class with module name as Java's

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 12 22:35:38 PST 2015


On 01/12/2015 10:09 PM, tcak wrote:

 > It is just making everything dirty.
 > request.HttpSocketConnectionRequest
 > connection.HttpSocketConnection

You can name the files the same as their classes: 
HttpSocketConnectionRequest.d, etc.

 > I just want to create a file called "HttpSocketConnectionRequest.d", and
 > put "HttpSocketConnectionRequest" into it.

I have a feeling I still don't understand the question because I've just 
tried it and it works the same in D. (Edit: Yes, it works the same but I 
finally understood the question below.)

 > import HttpSocketConnectionRequest: HttpSocketConnectionRequest;

Ok, that works.

 > HttpSocketConnectionRequest.d
 > ==============
 > module net.http.HttpSocketConnectionRequest;

So, you create the directory hierarchy net/http and put 
HttpSocketConnectionRequest.d in it. Ok.

 > class HttpSocketConnectionRequest{}
 >
 >
 > With this, above solution doesn't work unfortunately. You cannot do that
 > with that solution:
 >
 > auto req = new net.http.HttpSocketConnectionRequest();

Oh! Finally I see what you mean. So, this alreday works:

     auto h = new net
                  .http
                  .HttpSocketConnectionRequest
                  .HttpSocketConnectionRequest();

but you want this to work:

     auto h = new net
                  .http
                  .HttpSocketConnectionRequest();

(If so, why didn't say so? :) )

And you get the following error:

Error: module net.http.HttpSocketConnectionRequest is used as a type

Yeah, net.http.HttpSocketConnectionRequest is a module. :-/ I don't know 
a solution to this problem.

Ali



More information about the Digitalmars-d-learn mailing list