'operator!='问题的模糊过载

时间:2015-03-18 23:49:49

标签: c++ atl mingw-w64

我正在将一些基于ATL的标头移植到Mingw中,并遇到了此代码的问题

    CComBSTR bstrHelpFile; 
        hr = pTypeLib->GetDocumentation(-1, NULL, NULL, NULL, &bstrHelpFile);

        if (SUCCEEDED(hr) && bstrHelpFile != NULL)
        {
           ..
        }

我得到的错误消息是

C:\mingw64\opt\atlmfc\include/atlbase.h:5882:37: error: ambiguous overload for 'operator!=' (operand types are 'ATL::CComBSTR' and 'long long int')
   if (SUCCEEDED(hr) && bstrHelpFile != NULL)
                                     ^
C:\mingw64\opt\atlmfc\include/atlbase.h:5882:37: note: candidates are:
C:\mingw64\opt\atlmfc\include/atlbase.h:5882:37: note: operator!=(BSTR {aka wchar_t*}, BSTR {aka wchar_t*}) <built-in>

这是来自ATL标题atlbase.h

的代码

有关如何解决此问题的任何建议?

1 个答案:

答案 0 :(得分:0)

显然,问题出现在operator !=类的CComBSTR的多个版本中。最有可能修复/解决此问题的方法是使用CComBSTR.Length()成员函数:

if(SUCCEEDED(hr) && bstrHelpFile.Length())
{
    // ...

原因是NULLBSTR的有效值,如果要检查字符串是否为空,则需要考虑该值可以是空指针和有效指针零长度字符串。