Implicit constructor call
Marcin Kuszczak
aarti at interia.pl
Fri Jan 12 13:49:27 PST 2007
Chris Nicholson-Sauls wrote:
> LeoD wrote:
>> Hi,
>> can constructors be called implicit in D? Example:
>
> You can get this using typesafe variadic arguments:
> # class Foo {
> # this (int i) { }
> # }
> #
> # void test (Foo f ...) { }
> #
> # int main () {
> # test(100);
> # return 0;
> # }
>
> See: http://digitalmars.com/d/function.html
> Heading: Variadic Functions
> Subheading: Typesafe Variadic Functions
>
Interesting. I didn't know that. Could be useful, but to say true I think
that syntax/semantic is really strange...
>>
>> And why are there no templated constructors in D? Example:
>>
>
> Because constructors are not virtual... or at least that's the explanation
> given in
> compiler errors with this. Seems more like just a special case. I was
> actually a little bit disappointed myself, though the use cases seem to be
> pretty niche.
As I know constructors in C++ are also not virtual, but they can be
templated. I don't get connection here...
It could be useful for variant classes which could be constructed with
different types. I couldn't translate Boost::Any well because of that
problem (there is enhancement request on bugzilla).
--
Regards
Marcin Kuszczak (Aarti_pl)
-------------------------------------
Ask me why I believe in Jesus - http://zapytaj.dlajezusa.pl (en/pl)
Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/
-------------------------------------
More information about the Digitalmars-d
mailing list