计算机应用 | 古代文学 | 市场营销 | 生命科学 | 交通物流 | 财务管理 | 历史学 | 毕业 | 哲学 | 政治 | 财税 | 经济 | 金融 | 审计 | 法学 | 护理学 | 国际经济与贸易
计算机软件 | 新闻传播 | 电子商务 | 土木工程 | 临床医学 | 旅游管理 | 建筑学 | 文学 | 化学 | 数学 | 物理 | 地理 | 理工 | 生命 | 文化 | 企业管理 | 电子信息工程
计算机网络 | 语言文学 | 信息安全 | 工程力学 | 工商管理 | 经济管理 | 计算机 | 机电 | 材料 | 医学 | 药学 | 会计 | 硕士 | 法律 | MBA
现当代文学 | 英美文学 | 通讯工程 | 网络工程 | 行政管理 | 公共管理 | 自动化 | 艺术 | 音乐 | 舞蹈 | 美术 | 本科 | 教育 | 英语 |

C++类的动态组件化技术(10)

2013-10-19 01:11
导读:ATL派生类对应的模板基类定义如下: /**************************************************************************** 模板类CAtlInheritItf,继承了基接口IBaseItf方法的实现, 同时

ATL派生类对应的模板基类定义如下:

/****************************************************************************

  模板类CAtlInheritItf,继承了基接口IBaseItf方法的实现,

  同时提供了IInheritItf的实现,可以将IInheritItf接口作为基接口共供其它接口继承

****************************************************************************/

template <class T, class Q, const IID* piid, const GUID* plibid = &CComModule::m_libid>

class ATL_NO_VTABLE CAtlInheritItf : public CAtlBaseItf<T, Q, piid, plibid>

{

public:

       // 派生接口方法“InheritFunc”,在此模板类内实现

       STDMETHOD(InheritFunc)()

       {

              m_pCPPObj->InheritFunc();

              return S_OK;

       }

};

更改IInheritItf接口的IDL定义:

[

       object,

       uuid(8F3902DF-DA55-4802-AB8A-958AFF45B2F4),

       dual,

       helpstring("IBaseItf Interface"),

       pointer_default(unique)

]

// 基接口从ICPPObjSeeker派生

interface IBaseItf : ICPPObjSeeker

{

       [id(1), helpstring("IBaseItf Method")] HRESULT BaseFunc();

};

[

       object,

       uuid(AFEBD472-4BEC-45CE-A5A2-E37537C4744A),

       dual,

       helpstring("IInheritItf Interface"),

       pointer_default(unique)

]

// IInheritItf接口从IBaseItf接口派生

interface IInheritItf : IBaseItf

{

       [id(11), helpstring("IInheritItf Method")] HRESULT InheritFunc();

};

最后,更改ATL派生类的模板基类:

class ATL_NO_VTABLE CATLInherit :

       ……,

       public CAtlInheritItf<CInheritItfImplement, IInheritItf, &IID_IInheritItf, &LIBID_CPP2ATLLib>

{

       ……

};

  现在,通过IInheritItf,我们可以使用IBaseItf的所有方法,实现了接口的继承。

上一篇:家庭自动化系统 下一篇:没有了