On Fri, 09 Oct 2009 21:50:48 +0200, Yigal Chripun <yigal...@gmail.com> wrote:
>On 09/10/2009 19:53, Max Samukha wrote: >> On Fri, 09 Oct 2009 11:40:43 -0500, Andrei Alexandrescu >> <seewebsiteforem...@erdani.org> wrote: >> >>> I'm talking with Sean and Walter about taking the first step towards >>> eliminating delete: defining function clear() that clears the state of >>> an object. Let me know of what you think. >>> >>> One problem I encountered is that I can't distinguish between a default >>> constructor that doesn't need to exist, and one that was disabled >>> because of other constructors. Consider: >>> >>> class A {} >>> class B { this(int) {} } >>> >>> You can evaluate "new A" but not "new B". So it's legit to create >>> objects of type A all default-initialized. But the pointer to >>> constructor stored in A.classinfo is null, same as B. >>> >>> Any ideas? >>> >> >> The notion of default constructor is not quite clear. >> >> class A >> { >> this(int a = 22) {} >> } >> >> Should A be considered as having a default constructor? >> >> class B >> { >> this(int) {} >> } >> >> Should passing int.init to B's constructor be considered default >> construction? If yes, we could recreate B using the init value. But >> then: >> >> class C >> { >> this(int a) {} >> this(int a, int b) {} >> } >> >> Which constructor to call? The one with fewer parameters? What if >> there are overloaded constructors with identical number of parameters? >> Should we explicitly mark one of the constructors as default? > >I agree. classinfo.defaultConstructor should be replaced by an array of >all the constructors. Only when the array is empty you assume the >existence of the default compiler generated constructor. I'd prefer complete runtime information for all members. The problem is I do not understand what 'default constructor' and 'default construction' means in D for classes that have explicit constructors with parameters. How to automatically construct this cl ass: class B { this(int a = 22) {} } ? For example, Object.factory will always return null for B, which is an arbitrary limitation. class C { this(int a) {} } For C, the "default constructor" should probably be generated like this: void C_ctor(C c) { c.__ctor(int.init); } etc. Otherwise, I cannot see how one can reconstruct an instance of C in 'clear'.