Can we have "Virtual Constructors"?

Answer Posted / meet

Constructor cannot be virtual. Because C++ is statically typed language. It is meaningless to the C++ compiler to create the object polymorphically. But it is possible to achieve behaviour like virtual constructor. This can be done by using factory design pattern.
Visit this link to know more about virtual constructor:
http://www.geeksforgeeks.org/advanced-c-virtual-constructor/

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is data binding in c++?

514


Explain storage qualifiers in c++.

629


why and when we can declar member fuction as a private in the class?

1614


What is guard code in c++?

652


Are strings immutable in c++?

668






How to tokenize a string in c++?

616


What is polymorphism & list its types in c++?

635


Why struct is used in c++?

633


How do you instruct your compiler to print the contents of the intermediate file showing the effects of the preprocessor?

588


When should you use global variables?

641


How do I tokenize a string in c++?

616


What is object oriented programming (oop)?

635


Can c++ do everything c can?

612


What is an object in c++?

625


Why was c++ made?

662