Modules named
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Wed Apr 12 09:56:50 PDT 2006
AgentOrange wrote:
> In article <e1i6gi$14oj$2 at digitaldaemon.com>, Hasan Aljudy says...
>
>>Chris Nicholson-Sauls wrote:
>>
>>>It isn't perfect, but it appears there is now a way to have modules
>>>named 'object' or at least according to a cheap little test I just ran.
>>>The trick is to explicitly import 'object' in your own 'object'. Let me
>>>show you what I mean:
>>>
>>># module test;
>>>#
>>># private import std.stdio ;
>>>#
>>># private import foo.object ;
>>>#
>>># void main () {
>>># FooObject foo = new FooObject ;
>>># writefln("%s", foo.toString);
>>># }
>>>
>>># module foo.object;
>>>#
>>># import object;
>>>#
>>># class FooObject : Object {
>>># public char[] toString () { return "<<FooObject>>"c; }
>>># }
>>>
>>>This compiles and runs fine for me, DMD 0.153 on Windows.
>>>
>>>-- Chris Nicholson-Sauls
>>
>>but this module is foo.object, which is totally different from object.
>>
>>There shouldn't be a problem with creating a module foo.object, it
>>wouldn't conflict with object anyway. At least that's what I think.
>
>
>
> I think the original problem was you cannot declare a class with the name Object
>
>
>
You can, however, declare a class named foo.object.Object, or even just foo.Object. You
just have to be very careful about the declerations of other classes in modules that
import your module declaring an "Object" class. In other words, in any module importing
"foo" (which declares "Object") you cannot declare "orphan" classes because they are
actually silently declared as children of ".Object". Now, it is possible that one could
now do this:
# module bar;
#
# private import foo; // declares class Object
#
# alias foo.Object FObject ;
# alias .Object OBJECT ; // note the "."
#
# class BarClass : OBJECT {
# public this () {
# prop = new FObject;
# }
#
# protected FObject prop;
# }
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-announce
mailing list