std::string text = "......"; char->freq std::map< char, int > freq; for ( char const & ch : string ) { ++freq[ ch ]; } freq[ '\' ] class C { int i; public: C( int i = 0 ) : i(i) {} void Print() const { std::cout << i; } bool operator<( C const& arg2 ) const { return i freq; std::map< C*, int > freq; by default std::map will use comparison defined by STL like this deafult: std::less will use namespace std { template struct less { bool operator() ( T const p1, T const p2 ) const { return p1 < p2; } }; } which will be instatiated as (syntax below is illegal) struct std::less { bool operator() ( C* const p1, C* const p2 ) const { return p1 < p2; // pointer comparison } }; Solution: ========= client's code ----------- namespace std { // open std namespace template <> // and defined specialization for C* struct less { bool operator() ( C const * p1, C const * p2 ) const { return *p1 < *p2; // object comparison } }; } std::map< C*, int > freq;