lundi 8 octobre 2018

Using set of function pointers c++

I am trying to create a set of function pointers in c++ but getting error while inserting / deleting elements from it.

#include<bits/stdc++.h>
using namespace std;

void func(int x) {
  cout<<x;
}

int main() {
  set <function<void (int)>> mine;
  mine.insert(func);
  return 0;
}

i am getting error /usr/include/c++/6/bits/stl_function.h:386:20: error: no match for ‘operator<’ (operand types are ‘const std::function’ and ‘const std::function’). I think that this problem is because of operator that will be used to compare set values , can someone suggest how to make this work ? How can i write a comparator for function pointers in this case ?

Aucun commentaire:

Enregistrer un commentaire