How can I include arguments in a function pointer?
This code creates a function pointer that can add two ints:
int addInt(int n, int m) {
return n+m;
}
int (*functionPtr)(int,int);
functionPtr = addInt;
(*functionPtr)(3,5); // = 8
For instance, I want to make a function pointer where the first argument is always 5, so that the function takes one int and adds five. And another one where the first argument is 8.
Is this possible using addInt? Something like:
// make-believe code that of course won't work
int (*functionPtr)(int);
functionPtr = addInt(5);
(*functionPtr)(3); // = 8
(*functionPtr)(9); // = 14
std::bindto do it.