My requirement is to store some functions for later execution with pre-defined arguments. Here is what I have tried
void doSomething(int i, int j) {
std::cout << "Sum " << i + j << std::endl;
}
int main(int argc, char *argv[]) {
std::vector<std::function<void(int, int)>> functionVector;
functionVector.push_back(std::bind(doSomething, 1, 2));
functionVector.push_back(std::bind(doSomething, 4, 2));
functionVector[0]();
functionVector[1]();
}
However this does not compile and gives following error
error: no matching function for call to object of type 'std::__1::__vector_base<std::__1::function<void (int, int)>,
std::__1::allocator<std::__1::function<void (int, int)> > >::value_type' (aka 'std::__1::function<void (int, int)>')
functionVector[0]();
^~~~~~~~~~~~~~~~~
How can I achieve this in C++11/14
?
Aucun commentaire:
Enregistrer un commentaire