x.sizeof vs typeid(x)

Robert Fraser fraserofthenight at gmail.com
Wed Feb 6 13:56:13 PST 2008


Sergey Gromov wrote:
> Sergey Gromov <snake.scaly at gmail.com> wrote:
>> foo(double x) {...}
>> property double distance() {return ...}
>>
>> foo(distance);   // OK
>> foo(distance()); // OK
>> foo = distance;  // error
> 
> Or even forbid to use the `double()' syntax for properties, and forbid 
> to overload properties with non-property functions.  In other words:
> 
> foo(distance()); // error, can't use call syntax for properties
> double distance(int precision) {...} // error, can't overload a property

 From my limited experience with C#, I know there's some kind of special 
property syntax. Maybe something like this would be a better solution?

private double myDistance;
public property distance
{
    double __get { return myDistance; }
    void __set(double val) { myDistance= val; }
    double* __addressOf { return &myDistance; }
}

double x = distance;    // x = distance.__get();
distance = 50.0;        // distance.__set(50.0);
double* p = &distance;  // p = distance.__addressOf();

And maybe add more property-properties as needed. This would make them 
first-class, fully interchangeable with variables.



More information about the Digitalmars-d mailing list