Is this intended behavior?

Jacob Carlborg doobnet at gmail.com
Sun Aug 10 13:54:57 PDT 2008


Auria wrote:
> Jacob Carlborg Wrote:
> 
>> Is this intended behavior?
>>
>> class id
>> {
>>      public int id;
>>
>>      public this ()
>>      {
>>      }
>>
>>      public this (int id)
>>      {
>>          this.id = id;
>>      }
>> }
>>
>> class NSObject : id
>> {
>>      public this ()
>>      {
>>      }
>>
>>      public this (int id)
>>      {
>>          this.id = id;
>>      }
>>
>>      id foo () // error here
>>      {
>>          return new id(3);
>>      }
>> }
>>
>> The compiler says: "Error: id is used as a type"
>> using the gdc bundle from the tango website on osx.
>> Apparently the compiler thinks the return type "id" refers to the member 
>> variable instead of the class.
> 
> I would say it's not a good diea to name both a class and its member variable the same name. (nyway, the convention is usually that class names begin with an upper case letter IIRC) Even if it was allowed, i'd discourage it, your use of "id" is very confusing, it's both a class and a variable

I know that the convention is that class names should begin with an 
uppercase letter and it's not very good to name a member variable the 
same as the class name but I have not created the library I'm just 
porting it. In this case "id" refers to the type "id" in Objective-c 
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_2_section_2.html#//apple_ref/doc/uid/TP30001163-CH11-SW3



More information about the Digitalmars-d mailing list