digitalmars.D.bugs - Can't overload functions in different modules
Currently it is impossible to have the compiler figure out which overloaded function to call when they are defined in different modules unless you specify a module path, even with aliases. ie, this code wont work: (the modules are in different files) <code> module foomod; struct Foo { char[] name; int value; } char[] toString(Foo foo) { return name; } module main; import foomod, std.string; uint i; Foo f; main() { writefln(toString(f)); // fails if "alias std.string.toString toString" is defined last writefln(toString(i)); // fails if "alias Foo.toString toString" is defined last // Both fail if neither are defined } </code> Now I know I could alias them as different symbols, but then you lose the whole point of overloading. -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 09 2004
You need to have two alias declarations. The following works: ---------------- foomod.d --------------------- module foomod; struct Foo { char[] name; int value; } char[] toString(Foo foo) { return foo.name; } ----------------- test.d -------------------------- module main; import foomod, std.string, std.stdio; alias std.string.toString toString; alias foomod.toString toString; uint i; Foo f; void main() { writefln(toString(f)); writefln(toString(i)); } -----------------------------------------------------
Nov 09 2004
On Tue, 9 Nov 2004 11:32:34 -0800, Walter <newshound digitalmars.com> wrote:You need to have two alias declarations. The following works: ---------------- foomod.d --------------------- module foomod; struct Foo { char[] name; int value; } char[] toString(Foo foo) { return foo.name; } ----------------- test.d -------------------------- module main; import foomod, std.string, std.stdio; alias std.string.toString toString; alias foomod.toString toString; uint i; Foo f; void main() { writefln(toString(f)); writefln(toString(i)); } -----------------------------------------------------huh... I swore I tried that... Whoops. (You didnt change any import stuff from 1.02, did you?) -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 10 2004