|
-
May 28th, 1999, 12:06 AM
#1
member function pointer in class
Hi,
My English is little, so some sentences can be wrong.
I'm trying to tell good English communication,
but it is not easy. Oops...
This topic is 'Function pointer of members'.
I had so many headaches for this problem.
This problem happened when I was coding numerical integration sub-routines
in the simulation program.
There are several integral methods such as RK, Gauss, Romberg, so on.
Users can be select integral methods in the program.
A member function can be integrated by calling integration member fucntion
pointer in simulation class.
If you have better idea for member function pointer, email me.
[email protected]
in header file,
typedef Result (CMyClass::*pf)(Arg,Arg,....);
Result func_name1(pf lpFunc);
Result func_name2(Arg,Arg,....);
Result func_name3(Arg,Arg,....);
...........
in source file,
void CMyClass::Callme(){
func_name1(func_name2);
func_name1(func_name3);
func_name1(func_name4);
......................
.......
}
Check the following exmaple.
I tested this code for VC++ 5.0 sp3, NT4.0 sp4.
class CMyClass{
.......
....
typedef long (CMyClass::*Functor)(int i);
//type definition for member functor
long FuncTest2(Functor lpFunc);
//receive member functor, calculated member.
//This Sub-routine can be for calculation.
long FuncTest(int i);
//sub-routine to be calculated
......
......
}
void CMyClass::Callme(){
long k=FuncTest2(FuncTest);//Functest2 calculate using FuncTest
CString str;
str.Format("%ld",k);
AfxMessageBox(str,MB_OK);//shows result
}
//Callme is called when silmuation start.
long CMyClass::FuncTest(int i)
{
return 10*i;
}
long CCMyClass::FuncTest2(Functor lpFunc)
{
return (this->*lpFunc)(10);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|