TDPL: Cross-module overloading

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Aug 2 18:35:09 PDT 2010


On page 148 it says there's a way to use a local alias in a module like so:

// inside calvin.d
alias hobbes.transmogrify transmogrify;

There is a required "import hobbes" before the alias declaration. That should probably be added to the errata.

But the example will not compile:

client.d(8): Error: hobbes.transmogrify at hobbes.d(4) conflicts with calvin.transm
ogrify at calvin.d(6)
client.d(11): Error: hobbes.transmogrify at hobbes.d(4) conflicts with hobbes.trans
mogrify at hobbes.d(4)

The errors go away if I remove the import to hobbes in the client module. Is this a DMD bug/not implemented feature or should removing the "import hobbes" in client.d be mentioned in TDPL?


The alternative, as stated in the book, is to use alias inside the client.d module instead, like so:

alias calvin.transmogrify transmogrify;
alias hobbes.transmogrify transmogrify;

But now the transmogrify function in the susie module is hidden, and the example won't compile:

client.d(14): Error: function alias client.transmogrify (uint) is not callable using argument types (string)
client.d(14): Error: cannot implicitly convert expression ("hi") of type string to double

Adding an alias to susie will make the example compile:

// inside client.d
alias calvin.transmogrify transmogrify;
alias hobbes.transmogrify transmogrify;
alias susie.transmogrify transmogrify;

Again, I'm not sure whether this was not mentioned in TDPL by accident or if it's a DMD bug.. Let me now if it's a bug and I'll report it. :)


More information about the Digitalmars-d mailing list