gpt4 book ai didi

c++ - 因错误使用 CComPtr 对象而导致的编译错误

转载 作者:行者123 更新时间:2023-11-30 04:40:35 27 4
gpt4 key购买 nike

我在我的类中定义了以下 CComPtr 对象和方法:

private:

CComPtr<IRawPdu>& getRawPdu();
// Returns the RawPdu interface pointer from the mRawPdu data member.
// mRawPdu is initialized, if necessary.

CComPtr<IRawPdu> mRawPdu;
// Initialized to 0 in the ctor. Uses lazy evaluation via getRawPdu().

在我的类的构造函数中,我通过初始化列表将 mRawPdu 初始化为 0。如果 mRawPdu 尚未初始化,则 getRawPdu() 方法使用惰性求值。

编译代码时出现如下错误:

Compiling...
topport.cpp
C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcomcli.h(295) : error C2664: 'ATL::AtlComPtrAssign' : cannot convert parameter 2 from 'const ATL::CComPtr<T>' to 'IUnknown *'
with
[
T=IRawPdu
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcomcli.h(292) : while compiling class template member function 'IRawPdu *ATL::CComPtr<T>::operator =(const ATL::CComPtr<T> &) throw()'
with
[
T=IRawPdu
]
sessionutilities.h(186) : see reference to class template instantiation 'ATL::CComPtr<T>' being compiled
with
[
T=IRawPdu
]
topglobals.cpp
C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcomcli.h(295) : error C2664: 'ATL::AtlComPtrAssign' : cannot convert parameter 2 from 'const ATL::CComPtr<T>' to 'IUnknown *'
with
[
T=IRawPdu
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcomcli.h(292) : while compiling class template member function 'IRawPdu *ATL::CComPtr<T>::operator =(const ATL::CComPtr<T> &) throw()'
with
[
T=IRawPdu
]
sessionutilities.h(186) : see reference to class template instantiation 'ATL::CComPtr<T>' being compiled
with
[
T=IRawPdu
]

对于可能导致此问题的原因有什么建议吗?

最佳答案

根据编译器给出的错误,它似乎无法推断出 IRawPdu 和 IUnknown 之间的转换。

它实际上是从 IUnknown 继承的吗?如果是这样,则可能是包含排序问题。您能否更深入地了解 IRawPdu 的层次结构

关于c++ - 因错误使用 CComPtr 对象而导致的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1067066/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com