上一节没有谈到的一幅图:
class CFoo : public IFoo {
void Func1() { /* ... */ }
void Func2(int nCount) { /* ... */ }
};
客户端可能是:
#include <IFOO.H // Don't need CFoo, just the interface
void DoFoo() {
IFoo *pFoo = Fn_That_Gets_An_IFoo_Pointer_To_A_CFoo_Object();
// Call the methods.
pFoo -> Func1();
pFoo -> Func2(5);
};
图中调用的步骤是:
1,
pFoo is dereferenced to find the vtable pointer in the object.
2,
- The vtable pointer is dereferenced and indexed to find the address of the function to be called.
3,
The function is called.