I found this code at here. How does the compiler know to use the function defined in classcomp?
struct/function
struct classcomp
{
bool operator() (const char& lhs, const char& rhs) const
{
return l开发者_StackOverflow社区hs<rhs;
}
};
Map Construction
map<char,int,classcomp> fourthm;
Constructor Prototypes from link above:
explicit map ( const Compare& comp = Compare(),const Allocator& = Allocator() );
template <class InputIterator> map ( InputIterator first, InputIterator last,const Compare& comp = Compare(), const Allocator& = Allocator() );
map ( const map<Key,T,Compare,Allocator>& x );
It uses the default-constructor for classcomp class so you get an object that has operator() defined and acts like a function.
精彩评论