Boost logo

Boost :

From: Theodore Witkamp (ted_at_[hidden])
Date: 2006-12-13 20:19:29


If you notice it's my_weak_ptr not boost::weak_ptr. Which can be used
in this way due to the implementation of get_pointer for that type.
I am using my own smart pointer classes.

Thanks

On 12/13/06, Jonathan Biggar <jon_at_[hidden]> wrote:
> 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_at_[hidden]
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>
>

-- 
Theodore Witkamp
CTO
RiffWare LLC
107 S Holliston Ave Apt 308
Pasadena, CA 91106
Mb. 626-372-0931

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk