dimanche 31 janvier 2016

Why we need additional () in std::hash

I want to create an hash for a custom type and I've seen that I must write something like

template <>
struct hash<MyClass>
{
  std::size_t operator()(const MyClass& key) const
  {
    return std::hash<int>()(key.getID());
  }
};

The code works but I don't understant why I must write

std::hash<int>()(key.getID());

instead of

std::hash<int>(key.getID());

What's the meaning of the middle () operator? I'm using Visual Studio 2013 and I've tried to see the std::hash source code, but I'm not good enough to understant it well...

Aucun commentaire:

Enregistrer un commentaire