constructor inheritance
Simen Kjaeraas
simen.kjaras at gmail.com
Tue Mar 4 10:46:07 PST 2008
On Tue, 04 Mar 2008 19:32:11 +0100, Elwis <elwispl at gmail.com> wrote:
> Hi.
> Is there any way to make constructor inherited automaticaly. I has many
> classes that have to have the same constructor, and I'd like not to copy
> it for each one.
A class constructor in D /is/ inherited automatically. From the spec
(http://www.digitalmars.com/d/2.0/class.html):
"If no call to constructors via this or super appear in a constructor,
and the base class has a constructor, a call to super() is inserted at the
beginning of the constructor."
If that for some reason does not work (it does for me), file a bug report,
and use an explicit call to super() in your constructors.
If you're speaking of several non-related classes having identical
constructors, I'd do it with a mixin.
template myConstructor
{
// do stuff here
}
this()
{
mixin(myConstructor);
}
If I have somehow completely missed your point, please do tell.
-- Simen
More information about the Digitalmars-d
mailing list