www.digitalmars.com         C & C++   DMDScript  

D - property name struct problem

reply Helmut Leitner <helmut.leitner chello.at> writes:
There is a mini problem with struct and size. You may
define a struct element named "size":

struct TEST {
   int size;
}

but you may have problems using it, because

   TEST t;
   use of ...  t.size 

is ambiguous. I had the problem with a function
pointer named "size" which was not callable.

I think it would be better to forbid the names of
"size", "init" and perhaps a few other property 
names as structure elements.

--
Helmut Leitner    leitner hls.via.at   
Graz, Austria   www.hls-software.com
May 11 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Helmut Leitner" <helmut.leitner chello.at> wrote in message
news:3EBEACDB.3AE9AE6E chello.at...
 There is a mini problem with struct and size. You may
 define a struct element named "size":

 struct TEST {
    int size;
 }

 but you may have problems using it, because

    TEST t;
    use of ...  t.size

 is ambiguous. I had the problem with a function
 pointer named "size" which was not callable.

 I think it would be better to forbid the names of
 "size", "init" and perhaps a few other property
 names as structure elements.

I know that's a problem, there are many ways to deal with it. I'm not sure which one is the best, so I thought I'd leave it be until there's more experience with it.
May 12 2003
parent "Luna Kid" <lunakid neuropolis.org> writes:
 struct TEST {
    int size;
 }

 but you may have problems using it, because

    TEST t;
    use of ...  t.size

 is ambiguous. I had the problem with a function
 pointer named "size" which was not callable.

 I think it would be better to forbid the names of
 "size", "init" and perhaps a few other property
 names as structure elements.

I know that's a problem, there are many ways to deal with it. I'm not sure which one is the best, so I thought I'd leave it be until there's more experience with it.

For one vote, I'd like D not to be obtrusive and interfere with my free choice of member names. So, instead of prohibiting the use of such good names as "size" (and even less good names, like "init"), I'd prefer almost anything else. ;) Cheers, Sz.
May 12 2003