L
Lars Munch
Hello
I would like to create a pointer to non-static member function of a
class and use it in the same class. I have tried the following:
============ Example begin ================
#include <stdio.h>
class c;
typedef void (c::*FP)(void);
class c
{
FP fp;
public:
void test_fp();
void test();
};
void c::test_fp() {
printf("test_fp\n");
}
void c::test() {
fp = &c::test_fp;
(this->fp)();
}
int main() {
c tfp;
tfp.test();
return 0;
}
============ Example end ================
But with this I get:
test.cpp:27: error: call to non-function `c::fp'
What am I doing wrong?
Thanks a lot
Best regards
-- Lars Munch
I would like to create a pointer to non-static member function of a
class and use it in the same class. I have tried the following:
============ Example begin ================
#include <stdio.h>
class c;
typedef void (c::*FP)(void);
class c
{
FP fp;
public:
void test_fp();
void test();
};
void c::test_fp() {
printf("test_fp\n");
}
void c::test() {
fp = &c::test_fp;
(this->fp)();
}
int main() {
c tfp;
tfp.test();
return 0;
}
============ Example end ================
But with this I get:
test.cpp:27: error: call to non-function `c::fp'
What am I doing wrong?
Thanks a lot
Best regards
-- Lars Munch