Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Assigning Method address to Pointer

Hi everybody,
Can anybody tell me the meaning of the line

void (*handle_it) (Event E) = AP_handler;
Here Event is another class defined and handle_it is a pointer variable that is being created.

Similarly even this line...
void (*handle_them) (Event E) = STA_handler;

The code is actually as follows:

void AP_handler(Event E)
{
//Some relevant code
}

void STA_handler(Event E)
{
// Some relevant code
}

int main()
{
Event x;
string input;
void (*handler_it) (Event E) = AP_handler;
void (*handle_them) (Event E) = STA_handler;
// the remaining part is some other relevant code.

}
[791 byte] By [rahularke] at [2007-11-11 10:26:44]
# 1 Re: Assigning Method address to Pointer
Hi,

void (*handle_it) (Event E) = AP_handler;

This code is actially assigning the function - pointer to the (function-pointer-)variable "handle_it".
handle_it can be assigned any function pointer of function that take an Event as parameter and return void.

Event someEvent;
handle_it(someEvent); // will call the function your variable handle_it points to, in your
// case AP_handler

Clearer?

Cheers,

D
drkybelk at 2007-11-11 20:58:52 >
# 2 Re: Assigning Method address to Pointer
Thanks
rahularke at 2007-11-11 20:59:52 >