开发者

error C2593: 'operator ==' is ambiguous

im just not following what the problem is, i receive this error message:

error C2593: 'operator ==' is ambiguous

when using this line of code in my project, this source compiled fine in VC6 but in my VC2010 i get the error message that wont allow compile. The source is below.

if( m_cardThreePlace == 0 ) {
    // generate player cards
    OnCardGenerate( 3 );

    OnWhatPlayerCardsActive( 3 );
    // set card for placement
    m_cardThreePlace = m_cardPlaceTemp;
    // clear placement temp
    m_cardPlaceTemp = _T("");
}

the declaration looks like this:

CString m_cardThreePlace;    

m_cardThreePlace = _T("");

the output window shows this:

BlackJack.cpp(239): error C2593: 'operator ==' is ambiguous C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\cstringt.h(2551): could be 'bool ATL::CStringT::operator ==(const ATL::CStringT &,char) throw()' [found using argument-dependent lookup] with [ BaseType=char, StringTraits=StrTraitMFC ] C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\cstringt.h(2400): or 'bool ATL::CStringT::operator ==(const ATL::CStringT &,const wchar_t *) throw(...)' [found using argument-dependent lookup] with [ 开发者_如何学C BaseType=char, StringTraits=StrTraitMFC ] C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\cstringt.h(2385): or 'bool ATL::CStringT::operator ==(const ATL::CStringT &,const char *) throw()' [found using argument-dependent lookup] with [ BaseType=char, StringTraits=StrTraitMFC ] while trying to match the argument list '(CString, int)'


The literal reason you're getting a compiler error is because CString provides three applicable overloads of the == operator: one for comparing to a single char, and two for comparing to C-style strings of the char* and wchar_t* varieties. Literal 0 could covert to any of these types, so the compiler isn't able to unambiguously figure out which you meant.

Now, the meaningful reason you're getting an error here is because == is intended to compare strings and you're trying to compare to a number. I'm guessing that you're trying to see if m_cardThreePlace is the empty string. If that's what you're going for, you can simply write:

if( m_cardThreePlace.IsEmpty() )

It's good that your code no longer compiles, as it's apparent that what you wrote and what you meant are two different things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜