String and opBinary

bearophile bearophileHUGS at lycos.com
Fri Jun 1 12:27:00 PDT 2012


Eyyub:

> I'd like to know why this following code doesn't compile :
>
> string opBinary(string op : "*")(string data, string word)
> {
> 	string temp;
> 	foreach(letter; word)
> 	{
> 		temp ~= data;
> 	}
> 	return temp;
> }

In D to work an overloaded operator like that needs to be a
class/struct method.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list