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 the use of main function in c++?

531


What does the following code do: int c=0; cout< a) Undefined *Updated* b) 01 c) 00

640


What happens when you make call 'delete this;'?

603


What is copy constructor? Can we make copy constructor private in c++?

599


What is an operator function? Describe the function of an operator function?

621






Is c++ a programming language?

598


Specify some guidelines that should be followed while overloading operators?

625


What do you mean by const correctness?

631


What do you mean by translation unit?

607


Is c++ fully object oriented?

553


What do nonglobal variables default to a) auto b) register c) static

652


What is the rule of three?

576


What is the use of 'using' declaration in c++?

634


Reads in the size of a square from the screen; 2. Prints a hollow square of that size out of “-“, “|” and blanks on screen; 3. Prints the same hollow square onto a text file. Your program should work for squares of all side sizes between 1 and 20. --- │ │ │ │ │ │ ---

1653


How do you find out if a linked-list has an end?

655