String and opBinary

Jonathan M Davis jmdavisProg at gmx.com
Fri Jun 1 14:26:39 PDT 2012


On Friday, June 01, 2012 22:18:50 Eyyub wrote:
> Why doesn't D allow a way to write operator overloading at
> scope-module level like in C++ ?(in this case)

Why would you need to? It only works when defining them for user-defined types 
anyway. So, having them be member functions makes perfect sense. And 
opBinaryRight solves the problem of needing the overload where the other type 
is on the left rather than the one that you're defining the overloaded operator 
for, which is the typical reason to define an overloaded operator as a friend 
function rather than a member function in C++.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list