但C是利用"structure"或"record"类型,将上包含双重的指向函数指针表的成员,实现接口描述,从而编写COM和使用COM的。如一个字典的接口:
struct IDictionaryVtbl;
struct IDictionary
{
IDictionaryVtbl *pVtbl;
};
struct IDictionaryVbtl
{
BOOL(* Initialize)(IDictionary *this);
BOOL(* LoadLibrary)(IDictionary *this,String);
BOOL(* InsertWord)(IDictionary *this,String,String); &n
C与C++接口实现比较
最新推荐文章于 2024-10-11 15:13:37 发布
本文比较了C和C++在实现接口上的差异。C语言通过结构体和指向函数指针的成员来描述接口,如IDictionary的例子,而C++则使用类和虚函数,实现更简洁。C++的类定义天然符合COM接口规范,且使用纯虚函数表示接口的抽象。客户端调用接口函数时,C++和C的调用方式在效果上是等价的。

最低0.47元/天 解锁文章
1008

被折叠的 条评论
为什么被折叠?



