www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Overloading with variadic functions

reply Vathix <chris dprogramming.com> writes:
I was thinking that it would be nice if D's variadic functions could be  
overloaded and that values are considered implicitly matched to the  
variadic function.

So the following would have an overload conflict,


void foo(...)
{
    printf("foo ...\n");
}

void foo(byte hi)
{
    printf("foo byte\n");
}

int main()
{
    foo(1);
    return 0;
}


because the int 1 only implicitly matches byte and implicitly matches with  
the '...'
and to my surprise, it did exactly what I wanted. Though I'm not sure if  
this was intentionally added to the compiler or it's just how it ended up,  
but it would be nice to keep it and have it documented.
Aug 22 2005
parent Vathix <chris dprogramming.com> writes:
On Mon, 22 Aug 2005 05:32:40 -0400, Vathix <chris dprogramming.com> wrote:

 I was thinking that it would be nice if D's variadic functions could be  
 overloaded and that values are considered implicitly matched to the  
 variadic function.
However, if typesafe variadic is involved, then values could still exactly match with it. Just non-typesafe would be implicit.
Aug 22 2005