[Bug 91] Inherited classes require base class to have a default constructor.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 7 09:55:55 PDT 2006


http://d.puremagic.com/bugzilla/show_bug.cgi?id=91





------- Comment #3 from smjg at iname.com  2006-04-07 11:55 -------
Yes, including C++ and Java.  If anybody could circumvent the requirement to
use a constructor simply by creating a derived a class, it would defeat the
point.

You can, however, put a protected constructor in the base class.  This is a
constructor created specifically for derived classes to base their constructors
on.  You would be able to completely override* a constructor if the base class
has a protected constructor that does nothing.  But can you think of an example
in which this would make sense?

* Actually, constructors don't override as such.  A constructor is a member
only of the class in which it is defined, not of any derived classes.  Hence if
the base class has no default constructor, then when deriving a class from it
you must explicitly define a constructor.


-- 




More information about the Digitalmars-d-bugs mailing list