Question:
Can we have "Virtual Constructors"?
Answer:
Yes we cannot have virtual constructors. But if the need arises, we can simulate the implementation of virtural constructor by calling a Init method from the constructor which, should be a virtual function. Source: CoolInterview.com
We can't have virtual constructos. Reason being, contructor is called to create the object of the given class(meaning Object doesn't exist) but to have virtual fuction(contructor is also a function), we need to have virtual table ready. And virtual table will be created only after the Object will be created. Source: CoolInterview.com
Answered by: Vineet | Date: 11/11/2009
| Contact Vineet
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.
|