开发者

How to call a function when using a map constructor?

开发者 https://www.devze.com 2023-04-13 01:05 出处:网络
I found this code at here.How does the compiler know to use the function defined in classcomp? struct/function

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消