无序地图中的std :: pair

时间:2015-06-12 20:47:24

标签: c++ loops set unordered-map std-pair

我已经提取了我的代码部分,以显示我认为导致错误的部分。

        typedef unordered_multimap<string , ItemPtr > StringToItemMultiMap;

        void Library::multiMapItemWithKeys ( StringToItemMultiMap * map , ItemPtr itemPtr , StringSet keySet )
    {
        StringSet::iterator it;
        for ( it = keySet.begin ( ); it != keySet.end ( ); ++it )
        {
            pair< string , ItemPtr > aPair ( *it , itemPtr );
            map->insert ( aPair );
        }
    }

我有这个运算符重载:

    bool operator<(const ItemPtr & ip1, const ItemPtr & ip2)
    {
        bool result;
        if ( ip1.getPtr ( )->getTitle ( ).compare ( ip2.getPtr ( )->getTitle ( ) ) < 0 )
            result = true;
        else
            result = false;
        return result;
    }

这是一个典型的错误:

    1>------ Build started: Project: asgmt04, Configuration: Debug Win32 ------
    1>  Library.cpp
    1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xhash(672): error C2675: unary '++' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
    1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\unordered_map(632) : see reference to function template instantiation 'void std::_Hash<std::_Umap_traits<_Kty,_Ty,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,true>>::insert<_Iter>(_Iter,_Iter)' being compiled
    1>          with
    1>          [
    1>              _Kty=std::string
    1>  ,            _Ty=ItemPtr
    1>  ,            _Hasher=std::hash<CustomType>
    1>  ,            _Keyeq=std::equal_to<CustomType>
    1>  ,            _Alloc=std::allocator<std::pair<const std::string,ItemPtr>>
    1>  ,            _Iter=std::string
    1>          ]

任何人都知道发生了什么事吗?

0 个答案:

没有答案