digitalmars.D - Implicit constructor call
- LeoD (20/20) Jan 12 2007 Hi,
- Marcin Kuszczak (11/41) Jan 12 2007 Same here. They are not templated in D, but would be nice if they will.....
- Chris Nicholson-Sauls (19/48) Jan 12 2007 You can get this using typesafe variadic arguments:
- Marcin Kuszczak (15/44) Jan 12 2007 Interesting. I didn't know that. Could be useful, but to say true I thin...
Hi, can constructors be called implicit in D? Example: class Foo { this(int i) { } } void test(Foo f) { } int main() { test(100); // Here Foo.this(100); should get called return 0; } And why are there no templated constructors in D? Example: this(T)(T parameter) { }
Jan 12 2007
LeoD wrote:Hi, can constructors be called implicit in D? Example: class Foo { this(int i) { } } void test(Foo f) { } int main() { test(100); // Here Foo.this(100); should get called return 0; }No. But I agree that it could be nice addition to D.And why are there no templated constructors in D? Example: this(T)(T parameter) { }Same here. They are not templated in D, but would be nice if they will... Hopefully Walter will add above features in future releases of DMD... -- 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/ -------------------------------------
Jan 12 2007
LeoD wrote:Hi, can constructors be called implicit in D? Example: class Foo { this(int i) { } } void test(Foo f) { } int main() { test(100); // Here Foo.this(100); should get called return 0; }You can get this using typesafe variadic arguments: See: http://digitalmars.com/d/function.html Heading: Variadic Functions Subheading: Typesafe Variadic FunctionsAnd why are there no templated constructors in D? Example: this(T)(T parameter) { }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. -- Chris Nicholson-Sauls
Jan 12 2007
Chris Nicholson-Sauls wrote:LeoD wrote:Interesting. I didn't know that. Could be useful, but to say true I think that syntax/semantic is really strange...Hi, can constructors be called implicit in D? Example:You can get this using typesafe variadic arguments: See: http://digitalmars.com/d/function.html Heading: Variadic Functions Subheading: Typesafe Variadic FunctionsAnd 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/ -------------------------------------
Jan 12 2007