The compiler inserts code into the beginning of the constructor that initializes the VPTR. Is this operation influenced by whether the constructor is the default one or it is explicitly declared? Is there any difference between the two?
Asked
Active
Viewed 62 times
-1
-
4For a polymorphic class, there will always be a vtable. – John Dibling Oct 27 '14 at 19:55
-
2It's implicit; there is nothing you can do to change or remove this behavior. – cdhowie Oct 27 '14 at 19:56
-
2There is no "vptr" in C++, not in a way that you can know or should care about. Who even got you onto the idea that you should make something up and then worry about it? – Kerrek SB Oct 27 '14 at 19:56
-
2Who knows? This is far into implementation-specific territory. The standard doesn't mandate, or even suggest, how virtual functions should be implemented. – molbdnilo Oct 27 '14 at 20:19
1 Answers
3
It will always be inserted, it has to be for polymorphism to work, at least the way compilers typically have it implemented. It will be initialized always, the constructors you declare (or don't declare) are irrelevant.
Or, hey, maybe it won't (although I do not know any compilers that behave this way), all you need to care about is that polymorphism works, and will always work no matter what constructors you have declared.

Jason C
- 38,729
- 14
- 126
- 182