I am trying to call function pointer using class pointer and compiler
is not allowing it.
//================================================== =
#include <stdio.h>
class TestClass
{
public:
int func1(int a) {
printf("\nTestClass:func1 a = %d\n", a);
return a;}
TestClass() { fptr = &TestClass::func1; }
int (TestClass::*fptr)(int);
};
int main()
{
TestClass* T1 = new TestClass;
int result = (T1->*fptr)(4); // compiler says undeclared identifier
delete T1;
return 0;
}
whereas at the same it works
#include <stdio.h>
class TestClass
{
public:
int func1(int a) {
printf("\nTestClass:func1 a = %d\n", a);
return a; }
TestClass() {
fptr = &TestClass::func1; }
int (TestClass::*fptr)(int);
int fptrwrapper(int a) {
(this->*fptr)(a);
return 0;}
};
int main()
{
TestClass* T1 = new TestClass;
T1->fptrwrapper(4);
delete T1;
return 0;
}
could you please point out where i am making mistake.. ???