簡體   English   中英

'operator!='問題的模棱兩可的重載

[英]ambiguous overload for 'operator!=' issue

我正在將一些基於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的代碼

關於如何解決此問題的任何建議?

顯然,問題出在CComBSTR類的operator !=多個版本中。 解決/解決此問題的首選方法是使用CComBSTR.Length()成員函數:

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

原因是NULLBSTR有效值,如果要檢查字符串是否為空,則需要考慮該值可以是null指針,也可以是指向零長度字符串的有效指針。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM