Semantics of postfix ops for classes

Christophe Travert travert at phare.normalesup.org
Wed Jul 25 09:02:24 PDT 2012


Don Clugston , dans le message (digitalmars.D:173192), a écrit :
> The question really is, do postfix ++ and -- make sense for reference 
> types? Arguably not. From a theoretical sense, the existing behaviour 
> does make sense, but in practice, every time it is used, it is probably 
> a bug.
> 
> The only other reasonable option I can think of would be to make class++ 
> be of type void, so that you could still write
> bar1++;
> but not bar2 = bar1++;
> since the existing behaviour can be achieved by writing bar2 = ++ bar1;

Similarly, the langage should provide a way to disable postfix++ on 
a struct, since a struct can be a reference type.


More information about the Digitalmars-d mailing list