нужно передать внутри одного класса методу имя другого метода как
параметр. пробую так:
#include <stdio.h>
class abc {
public:
int sum(int x, int y) { return x + y; }
int act(int (*f)(int, int), int x, int y) { return f(x, y); }
int res(int a, int x, int y) {
if(a == 1) {
return act(sum, x, y);
}
return 0;
}
};
int
main(int argc, char **argv) {
abc a;
printf("%d\n", a.res(1, 5, 6));
return 0;
}
$ g++ -Wall -c -o test.o test.cpp
test.cpp: In member function `int abc::res(int, int, int)':
test.cpp:11: error: no matching function for call to `abc::act(<unknown type>, int&, int&)'
test.cpp:7: note: candidates are: int abc::act(int (*)(int, int), int, int)
make: *** [test.o] Error 1
с обычными функциями (без классов) все работает номально
Форум —
Development

