Constructor inheritance? Why not?

Tofu Ninja via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 7 21:16:12 PDT 2015


On Monday, 8 June 2015 at 03:35:52 UTC, Jonathan M Davis wrote:
> On Monday, 8 June 2015 at 02:39:22 UTC, Tofu Ninja wrote:
>> Is there any reason why constructors are not inherited? All 
>> other methods are inherited, why not constructors?
>
> They're not polymorphic, and it doesn't make sense to call a 
> base class constructor on a derived class. I think that I heard 
> somewhere that C++11 added some sort of constructor 
> inheritance, so maybe there's something we could do that would 
> make sense, but in general, I don't see how the concept makes 
> any sense at all. Construction is intimately tied to the type 
> being constructed. It's as non-generic as you can get.
>
> - Jonathan M Davis

Their are plenty of examples where you would want a constructor 
to be inherited, exceptions being a good one. Currently if you 
have a base class with a constructor that you want all the sub 
classes to have as well, you simply have to just copy past them 
all over the place.


More information about the Digitalmars-d mailing list