Overloading an imported function

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Oct 21 05:27:54 PDT 2015


On Wednesday, October 21, 2015 02:05 PM, Shriramana Sharma wrote:

> When I've imported std.math which contains round(real), why is the
> compiler complaining about not being able to call the overload function
> defined in *this* module?

The functions don't form an overload set. You need to bring them together 
explicitly using `alias`:

----
import std.math;
alias round = std.math.round;
real round(real val, int prec) {...}
----

This is so to avoid function hijacking. See <http://dlang.org/hijack.html>.

> I don't see anything in http://dlang.org/module.html that says I cannot
> define an overload of an imported function. Did I miss something?

That page doesn't seem to mention overloads at all. 
<http://dlang.org/function.html#overload-sets> covers overload sets from 
different imports, but it doesn't mention this specific case where there is 
a local overload set, too.


More information about the Digitalmars-d-learn mailing list