How to check at compile time if Default Constructor for a class exists?
Bottled Gin via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jan 1 18:42:56 PST 2016
> It seems like saying that a constructor with all default
> arguments is not a default constructor is a distinction without
> meaning. What are you doing that you would care?
>
The Object.factory does not seem to consider a constructor with
default arguments as a defaultConstructor. Consider the following
code snippet. It works only when I uncomment line 3.
module foo; // 1
class Foo { // 2
// this() {} // 3
this(int n=0) {} // 4
} // 5
void main() { // 6
auto obj = Object.factory("foo.Foo"); // 7
assert(obj !is null); // 8
auto foo = cast(Foo) obj; // 9
assert(foo !is null); // 10
} // 11
More information about the Digitalmars-d
mailing list