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.