if i declare a class, then declare an instance of that class, when is the instance allocated on the heap (assuming it has member variables)?
The instance is allocated on the heap when you call new (or malloc() or another similar func). No sooner, no later.
where is the VMT stored, and when ?
With the memory of the class, when the class is created -
usually alongside the member variables in memory. Sorry, not thinking clearly. The pointer to the v-table is stored alongside the member variables (because it is a member variable - just a hidden one added by the compiler).
and there's just one VMT per class, right?
One VMT per class instance, yes.
[Edit:] I forgot about multiple inheritance. One VMT for each base class in each instance.
class Derived : BaseA, BaseB
One v-table for BaseA, one for BaseB.
[Edit 2:] Wow, really not thinking straight today. Read TheComet's post below. Each class definition will have it's own v-table, but each class instance just has a unique pointer to a v-table. BaseA and BaseB each have a pointer to a v-table. BaseA points to BaseA's v-table, but Derived inherits that pointer and changes it to point to Derived's custom BaseA v-table. BaseB has a pointer to BaseB's v-table, but Derived inherits that and changes the value to point to Derived's custom BaseB v-table.
non virtual method calls require no vmt lookup, correct?
Yes. And if the class itself has zero virtual functions, then it won't have any Virtual Method Table.
Wikipedia gives some examples here.
Edited by Servant of the Lord, 16 April 2014 - 10:37 AM.