R
Ramesh
Hi,
I am trying to create an array of pointers to member functions inside
my class. When I created a global array of type pfn & initialized with
member functions and copy it back to the member function pointer array
(Handlers) - compiler doesnt let me do that.
I got an error as below:
"invalid use of non-static member function bool test::func1(long int)"
I am looking for two things at this point
1) how to initialize the member array of pointers (I prefer to do that
in the constructor)
2) call them from a member function funcw by their index?
Here is my code:
using namespace std;
#include <iostream>
#define MAXFN 2
class test;
typedef bool (*pfn) (long);
class test {
private:
long var;
pfn Handlers[MAXFN];
public:
test();
bool func1(long);
bool func2(long);
bool funcw(long);
void reg();
};
test::test() {
}
bool test::func1(long _p1) {
var = _p1;
}
bool test::func2(long _p2) {
cout << var << endl;
cout << "New Value :" << var << endl;
}
bool test::funcw(long _i) {
}
void test::reg() {
}
main() {
test t1;
t1.func1(10);
t1.func2(20);
t1.funcw(1);
}
Thanks
/R
I am trying to create an array of pointers to member functions inside
my class. When I created a global array of type pfn & initialized with
member functions and copy it back to the member function pointer array
(Handlers) - compiler doesnt let me do that.
I got an error as below:
"invalid use of non-static member function bool test::func1(long int)"
I am looking for two things at this point
1) how to initialize the member array of pointers (I prefer to do that
in the constructor)
2) call them from a member function funcw by their index?
Here is my code:
using namespace std;
#include <iostream>
#define MAXFN 2
class test;
typedef bool (*pfn) (long);
class test {
private:
long var;
pfn Handlers[MAXFN];
public:
test();
bool func1(long);
bool func2(long);
bool funcw(long);
void reg();
};
test::test() {
}
bool test::func1(long _p1) {
var = _p1;
}
bool test::func2(long _p2) {
cout << var << endl;
cout << "New Value :" << var << endl;
}
bool test::funcw(long _i) {
}
void test::reg() {
}
main() {
test t1;
t1.func1(10);
t1.func2(20);
t1.funcw(1);
}
Thanks
/R