mardi 10 août 2021

no instance of overloaded function std::unordermap.insert

I declared a stream class, but when defining its member function, it always reports an error when I want to insert something into the private member unordered_map, I want to ask How to solve this? stream.h

#include <unordered_map>

class stream
{
private:
    std::unordered_map<size_t, std::string> word_count;
public:
    void reassemblestream() const;
};

stream.cpp

#include"stream.h"
using namespace std;
void stream::reassemblestream() const
{
    static  size_t a = 1;
    string fe = "dfi";
    word_count.insert({ 1,"dfs" });
    word_count.insert(make_pair(a, fe));
}

error happen in stream.cpp of word_count.insert funcion. This is the error information:

E1087 There is no overloaded function "std::unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>::insert [where _Kty=size_t, _Ty=std::string, _Hasher=std:: hash<size_t>, _Keyeq=std::equal_to<size_t>, _Alloc=std::allocator<std::pair<const size_t, std::string>>]" instance (object contains type qualifiers that prevent matching)

I use visual studio 2019.

Aucun commentaire:

Enregistrer un commentaire