代码之家  ›  专栏  ›  技术社区  ›  Will Gorman

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

  •  3
  • Will Gorman  · 技术社区  · 16 年前

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

    CList<IDispatchPtr, IDispatchPtr> list;
    

    但是,我遇到了几个类似于以下内容的编译错误:

    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;
    

    查看调用SerializedElements的MFC代码,问题似乎在于它采用了一个类型*,并且两者之间没有转换 IDispatch** and IDispatchPtr* . 这有什么办法吗?

    1 回复  |  直到 16 年前
        1
  •  6
  •   Phil Booth    16 年前

    因为这样 operator& CAdapt<> :

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