Question:
Why the constructor can't be virtual?
Answer:
A constructor can not be virtual because at the time when the constructor is invoked the virtual table (vtable) would not be available in the memory.
Virtual allows us to call a function knowing only the interfaces and not the exact type of the object. To create an object you need complete information. In particular, you need to know the what you want to create exactly. Hence call to a constructor can't be virtual.
Source: CoolInterview.com
Answered by: smitra | Date: 5/19/2008
| Contact smitra
A constructor can not be virtual because at the time when the constructor is invoked the virtual table (vtable) would not be available in the Source: CoolInterview.com
Answered by: sayyid mohammed raees | Date: 1/9/2010
| Contact sayyid mohammed raees
when compiler find virtual key word it will intitalize vptr inside the constructor. if you declare virtual for constructor where comipler can initialize vptr. Source: CoolInterview.com
Answered by: Ravindra | Date: 1/17/2010
| Contact Ravindra
Bcoz V-Table(which consists the address of all virtual member function of all derived class ) is initialized by the constructor and if you try to make the constructor itself as virtual then who ll initialize the V table Source: CoolInterview.com
Answered by: NaveeN | Date: 6/2/2010
| Contact NaveeN
constructor can not be virtual because for virtual inheritence is essential for being overriden and constructor cant be inherited. Source: CoolInterview.com
Answered by: ajay singh rathour | Date: 9/1/2010
| Contact ajay singh rathour
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|