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:
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> > *'开发者_StackOverflow中文版 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*
. Is there any way around this?
Because of the way operator&
is overloaded, you need to wrap the smart pointers in CAdapt<>
:
CList<CAdapt<IDispatchPtr>, CAdapt<IDispatchPtr> > list;
精彩评论