Problem with Point property

Chris Miller chris at dprogramming.com
Tue Mar 6 13:46:16 PST 2007


On Tue, 06 Mar 2007 16:29:14 -0500, Henning Hasemann <hhasemann at web.de>  
wrote:

>
> Hi all, say I have a structure Point and an attribute position like this:
>
> struct Point {
>   int x, y;
> }
>
> class Foo {
>   Point position;
> }
>
> So far, so good. Now I want to substitude the attribute with a property
> (because I want to react on changes of the position immediately)
> The setter is no Problem:
>
>   void position(Point p) { mPosition = p; react(); }
>
> The getter indeed is. If I wrote:
>
>   Point position() { return mPosition; }
>
> this would break expressions like
>
> Foo().position.x = 5;
>

This should be easy enough for the compiler to detect and automatically  
call the matching setter (if none, error). But the compiler doesn't even  
detect some basic operators on properties, so...



More information about the Digitalmars-d mailing list