E0304 no instance of overloaded function "std::map<_Kty, _Ty, _Pr, _Alloc>::insert [with _Kty=char, _Ty=std::string, _Pr=std::less<char>, _Alloc=std::allocator<std::pair<const char, std::string>>]" matches the argument list HuffmanEncoding C:\Users\hmeltz\source\repos\HuffmanEncoding\HuffmanEncoding\HuffmanTree.cpp 114
// Example program
#include <iostream>
#include <string>
#include <map>
using std::string;
using std::map;
int main()
{
string encodedChar = "test";
map<char, string> codeMap;
char temp = 'c';
//codeMap.insert(temp, encodedChar); // error: no matching function for call to 'std::map<char, std::basic_string<char> >::insert(char&, std::string&)'
codeMap.insert({temp, encodedChar});
}
It either takes:
(1) a single element as a parameter
(2) a position and a single element
(3) a range of iterators
(4) an initializer_list of values
None of those match what you were trying to call, hence the compiler error.
For insert (const value_type& val);,
Member type value_type is the type of the elements in the container,
defined in map as pair<const key_type, mapped_type>
So you need to insert a pair, not individual parameters. Using { } is an easy way to achieve this without writing out the full type of pair<char, string>(mychar, mystring).