Vector of maps with custom comparator

  c++

I am trying to create a vector of maps. Each map has a different comparator.

Here is what I have tried:-

#include<iostream>
#include<map>
#include<vector>

template <class T>
struct head {
  virtual bool operator() (const T& x, const T& y) const = 0;
};

template <class T>
struct greater: head<T> {
  bool operator() (const T& x, const T& y) const {return x>y;}
};

template <class T>
struct less: head<T> {
  bool operator() (const T& x, const T& y) const {return x<y;}
};

int main()
{
    std::vector<std::map<int, int, head<int>>> mp;
    return 0;
}

But I am getting an error that my operator() is pure virtual in head.

Please tell me what is the correct way to achieve this?

Source: Windows Questions C++

LEAVE A COMMENT