C++/c++

Advertisement


Question
Why c++ not having virtual constructor

Answer
Hello Sushil Sharma, thank you for the question.

In C++, the only modifier you can have on a constructor is the inline keyword.

Most people use virtual destructors because of inheritence, in the case of Abstract Base Classes, as to make sure that the function is overridden and the class is not instantiated. You automatically know that the derived class will have a destructor, so it seems the most suitable function to make virtual.

For a more detailed explanation of what virtual does, please look it up in the MSDN library, which can be found for free at http://msdn.microsoft.com

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.