Although, this code doesn't actually compile for me, it complains about line 30
Yeah, the code is C++1X. I guess I should have mentioned that.
If you are using C++98, you should have also got errors for lines 17 and 20. For C++98, you would need to modify them to something like:
typedef typename std::map< key_type, int>::iterator iterator ;
for( iterator iter = frequency_map.begin() ; iter != frequency_map.end() ; ++iter )
// etc.