We all know that polymorphisms in CPP depend on virtual tables and virtual pointers, so when are virtual tables generated? Is it before or after the constructor is executed? And where are the virtual watches stored?
We all know that polymorphisms in CPP depend on virtual tables and virtual pointers, so when are virtual tables generated? Is it before or after the constructor is executed? And where are the virtual watches stored?
VMT is implementation dependent, so topics should be limited to compilers implementations rather than cPP itself.
so when is the virtual table generated? Is it before or after the constructor is executed?
For Most compilers, virtual table pointer initializes _ _ vptr at constructor's initializer list.
< hr >and where are the virtual tables stored?
What confuses you is where _ _ vptr is (not VMT , because VMT just consists of the addresses of trivial non-virtual functions which can be invoked by _ vptr ), then:
Compilers have multiple choices (all as a hidden member), you can refer to here
Summary: Where is the _ _ vptr stored in an object (first or last are the usual answers).
Of course, you can implement VMT with c, then you will not ask such questions.
BTW, this is not good (even is a bad) question, because you even haven't searched it on google before asking, so-1.
< H2 > Update: < / H2 >Wikipedia is also your friend.