Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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 27-Feb-13 20:05pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100