ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  C++ General
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
How to construct virtual constructor
 Question Submitted By :: Shalini
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to construct virtual constructor
Answer
# 1
Constructors can't be virtual in C++.It is an error.The
destructors on the other hand can be virtual.
 
Is This Answer Correct ?    1 Yes 0 No
Richa
 
  Re: How to construct virtual constructor
Answer
# 2
there is no need to use vitual constructors in C++.
because the construction of the class tree will be happened
from the base class to child class.
 
Is This Answer Correct ?    0 Yes 1 No
Vishwa
 
 
 
  Re: How to construct virtual constructor
Answer
# 3
C++ doesn’t give any direct support to declare a virtual 
constructor as such. But we can have a virtual constructor 
by indirectly providing the mechanism.

As like ordinary virtual functions, a virtual constructor 
can exhibit different behaviors depending upon the request. 
That is, a virtual constructor can construct different 
types of objects on different requests. This implies the 
class hierarchy should be polymorphical.

This technique resembles two stage construction technique. 
To avoid breaking at the constructor of an object, we keep 
the heavy initialization code in a separate initializer 
function so that we get the minimum guarantee that the 
constructor won’t fail.
In this case, we first invoke the constructor and then 
invoke the initializer function. The advantage of this 
method is that we will have a better control of the 
construction.

For example,

CBrush blueBrush;  // Just an object. Must be initialized!
blueBrush.CreateSolidBrush(RGB(0,0,255));  // Blue brush.

Since I am running short of time, I hang on with this for 
the time being. I will add more details about the virtual 
constructor theory soon.
 
Is This Answer Correct ?    3 Yes 0 No
Mmszubeir
 
  Re: How to construct virtual constructor
Answer
# 4
Virtual constructors are not used in any case in c++, bcz
the construction order in c++ should always remains from
base to derived , no one can changed their construction
order, so no need to declare constructor as virtual. But if
anyone wants to make it virtual then it  is possible to make
a constructor virtual but it is against the OOPs.
 
Is This Answer Correct ?    1 Yes 0 No
Shakti Singh Khinchi
 

 
 
 
Other C++ General Interview Questions
 
  Question Asked @ Answers
 
What is your strongest programming language (Java, ASP, C, C++, VB, HTML,C#, etc.)? Microsoft20
What are the types of STL containers?  1
how can u create a doubly linked list with out using pointers?  1
1. What does the following do: void afunction(int *x) { x=new int; *x=12; } int main() { int v=10; afunction(&v); cout<<v; } a) Outputs 12 b) Outputs 10 c) Outputs the address of v Quark3
Do we have private destructors? Symphony9
When the design recommends static functions? Symphony1
how to swap two strings without using any third variable ?  3
What is difference between initialization and assignment? HP4
Write the program form Armstrong no in c++?  4
why the size of an empty class is 1  3
Memory is not a constraint. In a single iteration(NOTE: you can't go back), how will you find out the 10th last node/item in a linked list. Goldman-Sachs8
Explain the difference between 'operator new' and the 'new' operator? Lucent1
In C++ cout is: a) object b) class c) something else Lehman-Brothers10
What is design pattern? Samsung2
What and all can a compiler provides by default? HP3
What are the different types of Storage classes?  3
Evaluate: int fn(int v) { if(v==1 || v==0) return 1; if(v%2==0) return fn(v/2)+2; else return fn(v-1)+3; } for fn(7); a) 10 b) 11 c) 1 Quark1
What is Virtual Inheritance? Wipro2
Describe functional overloading? HP3
The "virtual" specifier in a member function enables which one of the following? a) Monmorphism b) Late binding c) Metamorphism d) Solomorphism e) Inheritance Quark3
 
For more C++ General Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com