This is not about "When VTABLE is created?". Rather, when the VPTR should be initialized? Is it at the beginning/end of the constructor or before/after the constructor?
A::A () : i(0), j(0) -->> here ?
{
-->> here ?
//...
-->> here ?
}
This is not about "When VTABLE is created?". Rather, when the VPTR should be initialized? Is it at the beginning/end of the constructor or before/after the constructor?
A::A () : i(0), j(0) -->> here ?
{
-->> here ?
//...
-->> here ?
}
it's initialized between the constructors of base and derived classes:
It happens when raw memory is converted to Base object. It happens when Base object is converted to Derived object during construction of an object. Same obviously happens in reverse when destroying object. I.e. every time when type changes, the vtable pointer is changed. (I'm sure someone comments that vtables don't need to exists according to the std..)
The machinery for virtual calls (usually a v-table, but doesn't need to be) is set up during the ctor-initializer, after construction of base subobjects and before construction of members. Section
[class.base.init]
decrees:Actually, during construction of the base subobjects, the virtual function machinery exists, but it is set up for the base class. Section [
class.cdtor
] says:This msdn article explains it in great detali
There it says :
so..
A::A () : i(0), j(0)
{
-->> here !
//...
//
}
But be careful, let's say you have the class A, and a class A1 derived from A.