I am trying to create a pointer to a function that only requires some of the arguments when called and specifies the others at the time the pointer is created. For example, see the code below.
Of course, as written this code doesn't compile, but I think it should help you understand what I'm trying to do. I have programmed in lisp and this is very easy to do, I would think C++ should have a way of doing it.Code:int main() { // The function bar only takes one argument -> a // b and c are specified as 1 and 2 (respectively) at time of function creation int (*bar)(int a) = &foo( int, 1, 2); cout << bar(3) << endl; // should print 3 int (*bar)(int a) = &foo( int, 4, 5); cout << bar(3) << endl; // should print 12 } // foo takes 3 arguments, but b and c are only necessary when first called int foo(int a, int b, int c) { static int d = b + c; return a + d; }
Thanks in advance for any help.




Reply With Quote
