1
votes

I'm having a problem with toolset v120 and cannot compile my code, but it works fine with v140. My IntelliSense says:

IntelliSense: no instance of overloaded function "std::map<_Kty, _Ty, _Pr, _Alloc>::insert [with _Kty=std::string, _Ty=SHOPPURCHASE, _Pr=std::less<std::string>, _Alloc=std::allocator<std::pair<const std::string, SHOPPURCHASE>>]" matches the argument list

argument types are: (std::pair<ATL::CStringT<char, StrTraitMFC_DLL<char, ATL::ChTraitsCRT<char>>>, SHOPPURCHASE>)

BOOL SCHARDATA2::SETSHOPPURCHASE ( VECSHOP &vecSHOP )
{
    m_mapCharged.clear();
    DWORD dwSIZE = static_cast<DWORD>(vecSHOP.size());
    for ( DWORD i=0; i<dwSIZE; ++i )
    {
        const SHOPPURCHASE &sPURCHASE = vecSHOP[i];
        m_mapCharged.insert ( std::make_pair(sPURCHASE.strPurKey,sPURCHASE) );
    }

    return TRUE;
}
1

1 Answers

0
votes

The error is telling you that you are trying to insert a std::pair that contains a CString where a std::string is expected.

CString is not implicitly convertible to std::string, so you need an explicit conversion between them. Try this:

m_mapCharged.insert ( std::make_pair(std::string(sPURCHASE.strPurKey.c_str()), sPURCHASE) );

Alternatively: you can use operator[] instead of insert():

m_mapCharged[sPURCHASE.strPurKey.c_str()] = sPURCHASE;