virtual constructors

W

WaterWalk

why virtual destructors are possible but virtual constructors are not?

Virtual destructors are possible, because it's possible to delete a
pointer to base class. If virtual destructor is not used, it'll be
unknown what the pointer actually points: just a base class object or
a subobject of a derived class. If it's the latter case, then a
virtual destructor can guarantee that derived class destructor is
called.

But when a class is constructed, it is always clear which class to
construct. So there's no need to have virtual constructor. What's
more, virtual methods are mainly used to support polymorphism. In the
case of construction, polymorphism has no use.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top