www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - problem overloading functions with complex enum type

reply Eric <eric makechip.com> writes:
import std.stdio;

enum A : int { a, b };
enum B : int { a, b };
enum AS : string[2] { a = ["1","2"], b = ["3","4"] };
enum BS : string[2] { a = ["5","6"], b = ["7","8"] };

void func(A a)   { writeln("A");  }
void func(B b)   { writeln("B");  }
void funcs(AS a) { writeln("AS"); }
void funcs(BS b) { writeln("BS"); }

void test()
{
     func(A.a); // no compiler error
     funcs(AS.a); // compiler error: matches both funcs(AS) and 
funcs(BS)
}

void main(string[] args) { }

In the above code, the function with the simple enum type 
argument can
be overloaded, but the function with the complex enum type 
argument cannot be overloaded.
Is this a bug?

Thx.
Eric
Jul 08
next sibling parent Lamex <Lamex dfghjkl.iuyt> writes:
On Saturday, 8 July 2017 at 15:23:10 UTC, Eric wrote:
 import std.stdio;
check check one two
Jul 10
prev sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 07/08/2017 08:23 AM, Eric wrote:

 enum AS : string[2] { a = ["1","2"], b = ["3","4"] };
 enum BS : string[2] { a = ["5","6"], b = ["7","8"] };
 void funcs(AS a) { writeln("AS"); }
 void funcs(BS b) { writeln("BS"); }
     funcs(AS.a); // compiler error: matches both funcs(AS) and funcs(BS)
This looks like a bug to me. Ali
Jul 10