Reputation: 410
I was hoping maybe someone could help me solve my issue. I get a lovely
No matching function for call to object of type 'const pCompare'
struct pCompare
{
bool operator()( const std::string & str1, const std::string & str2 ) const
{
return str1.compare( str2 ) == 0;
}
};
std::string *t = new std::string ( "/test.html" );
std::map<std::string*, std::string, pCompare> test;
test.insert ( std::pair<std::string*, std::string> ( t, "héhé" ) );
std::cout << test.find(new std::string ("/test.html") )->second;
Thanks for your help !
Upvotes: 0
Views: 792
Reputation: 1017
First of all, do not do this, as it will screw up your map: You need an ordering function for the map, not an equality test.
Anyway, I guess you problem is that your key type std::string* but your function tests for string& . I haven't tried this, but this should do the trick:
bool operator()( std::string * str1, const std::string * str2 ) const
{
return *str1 < *str2;
}
Upvotes: 4