64,647
社区成员
发帖
与我相关
我的任务
分享
interface IUnknown
{
virtual HRESULT QueryInterface(REFIID iid,void **ppv);
virtual ULONG AddRef(void);
virtual ULONG Release(void);
};
interface INonDelegatingUnknown
{
virtual HRESULT NonDelegatingQueryInterface (REFIID riid, LPVOID *ppv) ;
virtual ULONG NonDelegatingAddRef(void) ;
virtual ULONG NonDelegatingRelease(void) ;
};
class A
{
public:
virtual void method1()
{
cout << "This is A`s method1()"<<endl;
}
virtual void method2()
{
cout << "This is A`s method2()"<<endl;
}
virtual void method3()
{
cout << "This is A`s method3()"<<endl;
}
};
class CallA
{
public:
virtual void callMethod1() = 0;
virtual void callMethod2() = 0;
virtual void callMethod3() = 0;
};
A testA;
CallA *pCallA = (CallA *)(&testA);
pCallA->callMethod1();
CMyComponent::CMyComponent(IUnknown *pOuterUnkown)
{
if (pOuterUnknown == NULL)
m_pUnknown = (IUnknown *)(INonDelegatingUnknown *)this;
else
m_pUnknown = pOuterUnknown;
[ ... more constructor code ... ]
}
|-------|<<--pCallA A类的虚函数表
|vptr --| ------->> |------|
|data1 | 0| vf1 |
|data2 | 1| vf2 |
|data3 | 2| vf3 |
|.... | |------|
|-------|
|