December 12, 2006 Is it a compiler bug? | ||||
---|---|---|---|---|
| ||||
Hello!
I would like to define two kinds of static opCall() in class like below:
static Any opCall(T)(T t) {
return (new Any()).assign(t);
}
static Any opCall() {
return new Any();
}
It seems for me properly coded (overloading should work as there is quite a big difference between function taking no parameters and function taking one parameter), but compiler complains:
..... : function Any.opCall conflicts with Any.opCall(T) at .....
Is it a compiler bug? Or maybe there is some workaround?
--
Regards
Marcin Kuszczak
(Aarti_pl)
|
December 13, 2006 Re: Is it a compiler bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marcin Kuszczak | Marcin Kuszczak wrote:
> Hello!
>
> I would like to define two kinds of static opCall() in class like below:
>
> static Any opCall(T)(T t) {
> return (new Any()).assign(t);
> }
>
> static Any opCall() {
> return new Any();
> }
>
> It seems for me properly coded (overloading should work as there is quite a
> big difference between function taking no parameters and function taking
> one parameter), but compiler complains:
>
> ..... : function Any.opCall conflicts with Any.opCall(T) at .....
>
>
> Is it a compiler bug? Or maybe there is some workaround?
>
I don't think its a bug, per se, but an effect of attempting to overload a function template with an ordinary function. Try providing a dummy specialization of the template instead, such as:
# static Any opCall (T) (T t) {
# return (new Any).assign(t);
# }
#
# static Any opCall () () {
# return new Any;
# }
-- Chris Nicholson-Sauls
|
Copyright © 1999-2021 by the D Language Foundation