|
-
April 15th, 2008, 02:38 PM
#1
Function Pointers in Classes
I have made class in c++ which has a function pointer.This function pointer needs to point to a function which is not a part of the class's methods i.e. a function that is in the main cpp.The address of the function to which the pointer points to is passed form the main cpp.However i am unable to get this to work i.e. i cannot store the address of the function in the function pointer as the function pointer has that additional "*this" pointer.I cannot make the function pointer static as each object 's function pointer points to a different function.Any fixes for this problem.
Program looks like this
class A
{
private:
void (*fnpointer)();
public:
void SetPointer(void (*fn)())
{
fnpointer=fn; //ERROR IS HERE.I DONT WANT TO MAKE fnpointer A STATIC FUNCTION
}
}
Main CPP
void func()
{
}
void main
{
A obj1;
obj1.SetPointer(&func);
}
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
|