Is this intended behavior?

Auria auria.mg at gmail.com
Sun Aug 10 08:26:40 PDT 2008


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



More information about the Digitalmars-d mailing list