MistyD
MistyD

Reputation: 17223

ambiguous overload for 'operator!=' issue

I am porting some ATL based headers into Mingw and came across problem with this code

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

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

The error message that I get is this

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>

This is the code from the ATL header atlbase.h

Any suggestions on how I could resolve this issue ?

Upvotes: 1

Views: 300

Answers (2)

user541686
user541686

Reputation: 210352

This issue arises because NULL isn't 0 in GCC. The solution is to use 0 instead, since there is an int overload precisely for this purpose.

Upvotes: 0

Roman Ryltsov
Roman Ryltsov

Reputation: 69632

Apparently, the problem is in multiple versions of operator != in CComBSTR class. Most likely your preferred way of fixing/resolving this problem is use of CComBSTR.Length() member function:

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

The reason is that NULL is valid value for BSTR and if you want to check if the string is empty, you need to take into consideration the value can be both null pointer and valid pointer to zero length string.

Upvotes: 0

Related Questions