Thread overview | |||||
---|---|---|---|---|---|
|
February 14, 2014 Object.factory and default constructor | ||||
---|---|---|---|---|
| ||||
The code below throws assertion failure. Documentation for Object.factory says that factory can create an object if the default constructor is present. So the question is -- Does D not consider this(int x=0); a default constructor? module test; class Bar { this(int x=0) {} } void main() { assert(Object.factory("test.Bar") !is null); } // Regards // Cherry |
February 14, 2014 Re: Object.factory and default constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cherry | On Friday, 14 February 2014 at 12:53:55 UTC, Cherry wrote:
> So the question is -- Does D not consider this(int x=0); a default constructor?
No, that is not a default constructor. Use overloading if you want it to be.
|
February 14, 2014 Re: Object.factory and default constructor | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cherry | On Friday, 14 February 2014 at 12:53:55 UTC, Cherry wrote:
> The code below throws assertion failure. Documentation for Object.factory says that factory can create an object if the default constructor is present.
>
> So the question is -- Does D not consider this(int x=0); a default constructor?
>
>
> module test;
> class Bar {
> this(int x=0) {}
> }
> void main() {
> assert(Object.factory("test.Bar") !is null);
> }
>
> // Regards
> // Cherry
Default constructor is always one declared without the arguments. Default arguments are pasted upon caller side and can't be figured out from TypeInfo.
|
Copyright © 1999-2021 by the D Language Foundation