是否可以将COM智能指针与CList集合一起使用

Wil*_*man 3 c++ mfc

我正在尝试使用COM智能指针(为其生成的包装类之一_com_ptr_t)创建一个CList 作为模板参数:

CList<IDispatchPtr, IDispatchPtr> list;
Run Code Online (Sandbox Code Playgroud)

但是我得到了几个类似于以下的编译错误:

error C2664: 'void __stdcall SerializeElements(class CArchive &,class _com_ptr_t<class _com_IIID<struct IDispatch,&struct __s_GUID _GUID_00020400_0000_0000_c000_00000000004 6> > *,int)' : cannot convert parameter 2 from 'struct IDispatch ** ' to 'class _com_ptr_t<class _com_IIID<struct IDispatch,&struct __s_GUID _GUID_00020400_0000_0000_c000_000000000046> > *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

它在使用常规指针时编译:

CList<IDispatch*, IDispatch*> list;
Run Code Online (Sandbox Code Playgroud)

查看调用SerializeElements的MFC代码,看起来问题是它需要一个TYPE*并且之间没有转换IDispatch** and IDispatchPtr*.有没有办法解决?

Phi*_*oth 6

由于方式operator&过载,您需要将智能指针包装在CAdapt<>:

CList<CAdapt<IDispatchPtr>, CAdapt<IDispatchPtr> > list;
Run Code Online (Sandbox Code Playgroud)