You are here:

C++/virtual constructor

Advertisement


Question
Hi,
Can u explain me,
when should i use virtual constructor/destructor,
how are they advantageous over the normal constructor/destructor.


Thanks
Chandu.B.S

Answer
Hello,

As far as common practice, when you inherit from a base class, make both the destructors virtual. This is allows for runtime binding with the compiler. Its like a way of making it "smart" and able to distinguish from when its calling a base or derived classes constructor/destructor. It is also a little slow, so if youre not inheriting from a class, dont use it.

I hope this information was helpful.

- Eddie  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Eddie

Expertise

I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

Experience

I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.