This is a blog for interview questions. The questions are primarily from certain web forums, BBS or books. The owner of this blog doesn't claim any copyright of those questions. The blog is established primarily to help the blog owner prepare job interviews.
Friday, June 17, 2011
Why there is no virtual constructor in C++?
Answer: If a function is virtual, there needs to be a pointer to the virtual function table so that you can look up in the vtable. However, when the constructor is executed, the pointer to vtable is not there yet, so you can't be able to locate vtable. Besides, constructor is usually in-lined. If it is a virtual function, it can't be in-lined
Labels:
C++,
programming
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment