-
August 1st, 2010, 03:23 AM
#1
Function Pointer & _closure
The trouble I'm facing is when I assign a function pointer to another.
Eg:
Code:
class foo
{
public:
bool (*myFunc)();
};
class Main
{
public:
void Procedure();
bool someFunc();
};
bool Main::someFunc ()
{
.
.
}
void Main::Procedure()
{
foo Obj;
Obj.myFunc = &someFunc; //Error
}
On assigning I get the error:
Cannot convert bool(*(_closure)())() to bool(*)(), but I don't know how to fix it. I know that it has something to do with the class owning the function & the function not being accessible without the class object, but how to fix it?
P.S. If the function is a global, then Obj.myFunc = &someGlobalFunc; works out fine
Any help is greatly appreciated.
Regards,
Nisheeth Barthwal
-
August 1st, 2010, 03:42 AM
#2
Re: Function Pointer & _closure
This is not a pointer to a non-static member function. This is a pointer to a non-class function, or static function.
Code:
bool Main::someFunc ()
{
return true;
}
void Main::Procedure()
{
foo Obj;
Obj.myFunc = &someFunc; //Error
}
Obj.myFunc is a non-static member function. You cannot assign a pointer of a non-static member function to a pointer to a static or non-class function.
http://www.parashift.com/c++-faq-lit...o-members.html
Regards,
Paul McKenzie
-
August 1st, 2010, 03:45 AM
#3
Re: Function Pointer & _closure
Thank you Paul for that link, I'm currently going through it.
Regards,
Nisheeth Barthwal
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
|