On Wednesday, 26 December 2012 at 17:11:31 UTC, Nick Treleaven
wrote:
On 26/12/2012 15:13, Maxim Fomin wrote:
The problem is that Exception class ctor requires at least one
explicit
argument
(https://github.com/D-Programming-Language/druntime/blob/master/src/object.di#L339).
To solve the problem in general case you can either supply
default
arguments for all ctor parameters or define parameter-less
ctor.
In your particular case because you cannot change Exception
you can
inherit not from Exception class but from intermediate one,
which does
one of the mentioned things:
import std.stdio;
class DException : Exception
{
this(string value = "") { super(value); }
}
Thanks for the reply. But actually I'm not looking to define a
parameter-less ctor for Exception subclasses, but to copy all
of a parent class's constructors into a subclass. This is nice
to do for Exception subclasses because sometimes I just want a
new type that behaves exactly the same, but has different RTTI.
But for other classes it can be useful if you want to override
some methods, but don't need to add/change any constructors,
apart from exposing them from the parent.
I've found a relevant discussion:
http://forum.dlang.org/post/op.u36pc3y4o7cclz@korden-pc
Currently dmd always creates implicit constructor for derived
classes if base class has a ctor. This can be prevented by
annotating ctor as a @disable, but it is unacceptable because you
have to write another constructor. So, there is no way for not
creating implicit constructor in a convenient way.