Constructor inheritance? Why not?

Atila Neves via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 7 22:56:21 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

Yes, modern C++ allows you to inherit constructors. It makes 
sense when you want to avoid the boilerplate of a constructor 
that does nothing but forward to the base class's constructor 
with the same signature.

Atila



More information about the Digitalmars-d mailing list