
Theodore Witkamp wrote:
Hi, I would like to get some feedback on some changes that I would like to make to boost::function for my own use only and I figured that this would be the best place for it.
I basically want to detect if there is a NULL "this" bound to a member function. I want to do this so that i can prevent dereferencing a NULL pointer when calling a member function. I hope the following code example will clarify. /////////////////////////////////////////////////////////////////////// // example code: /////////////////////////////////////////////////////////////////////// struct X { void f() { assert(this != NULL); } };
my_smart_ptr<X> sp_x = new X(); my_weak_ptr<X> wp_x = sp_x; boost::function0<void> _f = bind(&X::f,wp_x); assert(!_f.empty()); sp_x.reset(); // wp_x == NULL
if(!_f.empty()) { _f(); // This will fail } ////////////////////////////////////////////////////////////////////////
I don't see how that code can work anyway, since you can't use a weak_ptr to directly invoke X::f. -- Jonathan Biggar jon@levanta.com