|
-
August 26th, 2011, 12:43 AM
#1
Pointer to member function
Is there an actual advantage of using a pointer to member function ?
I think the syntax looks no good at all ? I can't comprehend much.
Code:
struct A
{
void somefunc(){}
};
void A::somefunc(int i)
{
int (*uglyPointI)(void*);
uglyPointI=i;
//do something
(*uglyPointI)((void*)&i);
}
Please, don't ask me what I am doing because I actually have no idea what I am doing either. I know I am making a bad question and I hope you would correct it and help me make a better question in the future...Thank you..
-
August 26th, 2011, 01:37 AM
#2
Re: Pointer to member function
Is there an actual advantage of using a pointer to member function ?
If you need one, it would be advantageous to have them.
I think the syntax looks no good at all ?
Admittedly, it seemed confusing to me the first time I glanced them, although I don't see any pointer to member functions in your example.
Code:
class TestClass
{
public:
int someMemberFunction(int n){ return n; }
};
int (TestClass::*memberFunctionPointer)(int) = &TestClass::someMemberFunction;
TestClass t;
int result = (t.*memberFunctionPointer)(42)
There is also std::function, which can be used to "point" to both functions and member functions.
Please, don't ask me what I am doing because I actually have no idea what I am doing either.
Perhaps you should wait until you do know what you are doing?
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
|