博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

COM-纯虚类-接口

Posted on 2011-08-11 21:15  ChessYoung  阅读(274)  评论(0编辑  收藏  举报
#include "stdafx.h"
#include
<ObjBase.h>
#include
<iostream>
using namespace std;

void trace(const char *pMsg) { cout << pMsg << endl; }
interface IX
{
virtual void __stdcall Fx1() = 0;
virtual void __stdcall Fx2() = 0;
};

interface IY
{
virtual void __stdcall Fy1() = 0;
virtual void __stdcall Fy2() = 0;
};
class CA :public IX, public IY
{
public:
virtual void __stdcall Fx1() { cout << "CA::Fx1" << endl;}
virtual void __stdcall Fx2() { cout << "CA::Fx2" << endl;}

virtual void __stdcall Fy1() { cout << "CA::Fy1" << endl;}
virtual void __stdcall Fy2() { cout << "CA::Fy2" << endl;}
};

int _tmain(int argc, _TCHAR* argv[])
{
trace(
"Client: Create an instance of the component.");
CA
*pA = new CA;

IX
*pIX = pA;
trace(
"Client: Use the IX interface.");
pIX
->Fx1();
pIX
->Fx2();

IY
*pIY = pA;
trace(
"Client: Use the IY interface.");
pIY
->Fy1();
pIY
->Fy2();

trace(
"Client: Delete the component.");
delete pA;

return 0;
}