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 new()is different from malloc()?

668


What happens if a pointer is deleted twice?

901


Why #include is used?

697


Can recursive program be written in C++?

731


What is difference between array and vector in c++?

637






Explain the difference between c & c++?

679


What is a pdb file?

632


What is ios :: in in c++?

735


Do the names of parameters have to agree in the prototype, definition, and call to the function?

689


What is a base class?

694


What are the defining traits of an object-oriented language?

786


What are shallow and deep copy?

713


What c++ is used for?

672


What are the rules about using an underscore in a c++ identifier?

716


What is the difference between public and private data members?

752