简体   繁体   English

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

[英]Is it possible to use COM smart pointers with the CList collection

I'm attempting to create a CList with a COM smart pointer (one of the wrapper classes generated for _com_ptr_t ) as the template parameter: 我正在尝试使用COM智能指针(为_com_ptr_t生成的包装类之一)创建一个CList作为模板参数:

CList<IDispatchPtr, IDispatchPtr> list;

However I get several compilation errors similar to: 但是我得到了几个类似于以下的编译错误:

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

It compiles when using regular pointers: 它在使用常规指针时编译:

CList<IDispatch*, IDispatch*> list;

Looking at the MFC code that calls SerializeElements it looks like the problem is that it takes a TYPE* and there's no conversion between IDispatch** and IDispatchPtr* . 查看调用SerializeElements的MFC代码,看起来问题是它需要TYPE *并且IDispatch** and IDispatchPtr*之间没有转换。 Is there any way around this? 有没有办法解决?

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

CList<CAdapt<IDispatchPtr>, CAdapt<IDispatchPtr> > list;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM