enum overloading

strtr strtr at spam.com
Sat May 22 15:08:37 PDT 2010


== Quote from Ary Borenszweig (ary at esperanto.org.ar)'s article
> Ary Borenszweig wrote:
> > strtr wrote:
> >> Sorry, should have included this :)
> >>
> >> ----
> >> module main;
> >> import std.string;
> >> import std.stdio;
> >>
> >> enum ENUM { A,B }
> >>
> >> char[] toString(ENUM e_){return "enum";}
> >>
> >> void main (){
> >>     writefln( toString(3) );
> >>     writefln( toString(ENUM.A) );
> >> }
> >> --
> >> main.d(10): Error: function main.toString (ENUM) does not match
> >> parameter types (int)
> >> main.d(10): Error: cannot implicitly convert expression (3) of type
> >> int to ENUM
> >> ----
> >
> > That's not overloading,
> Overloading is defining many functions with the same name but different
> type arguments.
>   you are expecting an implicit conversion from
> > int to ENUM. Maybe if you cast 3 to ENUM, but still... no ENUM value
> > will be found for 3. What are you trying to do?

Well, actually, I was expecting std.string.toString(int) to be called for the int
and my toString(ENUM) for the enum..?


More information about the Digitalmars-d-learn mailing list