opStar

Xinok xnknet at gmail.com
Sat Nov 10 08:06:49 PST 2007


Janice Caron wrote:
> Maybe Walter will add opStarAssign()?
> 
> (Nice call on the name, too!)

I don't think that would work. Unlike "n[]=", "*n=" is not it's own 
operator, it's two separate operators.


I was thinking, what if the return type is a pointer, then the compiler 
automatically dereferences the pointer? Take for example:

class N{
	int v;
	int* opStar(){ return &v; }
}

N obj = new N;
*obj = 10;

What if the compiler rewrites the last statement as:
*obj.opStar() = 10;


This wouldn't be the only operator with unusual behavior. D already has 
opEquals and opCmp, where the compiler will rewrite the expression 
similarly to this.



More information about the Digitalmars-d mailing list