|
I have a program in c++
in myclass.h
- class MyClass
- {
- public:
- MyClass();
- struct test_struct
- {
- //a is an array
- double *a;
- //sigma is a function pointer point to a member function of MyClass
- double (*sigma)(int, int);
- };
-
- void use_struct_example();
- private:
- double somefunction(int, int);
- }
- in myclass.cpp
- [CODE]
- //constructor
- MyClass::MyClass()
- {
- }
- MyClass::use_struct_example()
- {
- test_struct ts;
- int myarray[5] = {1,2,3,4,5};
- ts.a = myarray;
- ts.sigma = &MyClass::somefunction;
- //some other operation here.....
- }
- MyClass::somefunction(int a, int b)
- {
- }
复制代码
when compile this program, there are two error reported by compiler:
first one is ISO C++ forbids taking the address of an unqualified non-static member function to form a pointer to member function.
second one is can not convert from type MyClass:: to type double.....
is there any one can explain how funciton pointer can be used in c++, particularly when you are in the situaion that you have to use a library that written in C, and in your c++ code, you have to pass a member function's address to a struct member, which obviously also written in C, encoded in that library.....
any attempts to solove my problem is much appreciated.... |
|