user656925
user656925

Reputation:

How to call a function when using a map constructor?

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 lhs<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 );

Upvotes: 0

Views: 168

Answers (1)

sim642
sim642

Reputation: 769

It uses the default-constructor for classcomp class so you get an object that has operator() defined and acts like a function.

Upvotes: 1

Related Questions