Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am dealing with function pointers to classes member functions
and they are being set as callbacks etc.
Then, been invoked.
My question is I think it is a good idea to check the function
pointers whether they have been set to NULL etc.? right?
e.g., maybe before invoking them etc.??

Thanks.
Posted

It is always a good idea to do some research before asking a question. There were a couple of questions about member functions pointers in last few days and any of those answers would have been valuable for you.

Regarding a Zero check on pointers: The following sentence is so trivial that I am almost afraid to give that as an advice: It never hurts to check, but is also never a guarantee that a pointer is valid otherwise. You should make sure by other means (correct initialization) that your pointers (data pointer or member function pointers alike) have a valid value.

Of course, you can use the zero-value is indication that the member function pointer is not valid at the time, for example because no callback has been specified so far.
 
Share this answer
 
It is always a good idea to check before you invoke a call.

You can insert assert to check on debug time to make sure that function is not empty
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900