Operator overloading

The time has come to return to user-defined types and see how to implement operator overloads. It's important to note before we get started that D does not support operator overloads as free functions; they must be part of a class or struct declaration. We'll be turning away from templates for part of this discussion; some operator overloads are required to be templates, but others can either be templates or normal member functions. We'll look at the latter group first. For the official documentation on operator overloading, pay a visit to http://dlang.org/operatoroverloading.html.

Non-templated operator overloads

There are a handful of operator overloads that are not required to be templates. These cover the comparison operators, ...

Get Learning D now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.