Re: Glib::RefPtr and Pointer



On Thu, 2007-11-08 at 23:39 +0100, Andreas Volz wrote:
> Am Thu, 08 Nov 2007 08:52:44 +0100 schrieb Murray Cumming:
> 
> > Yes. You need to check pointers (or RefPtrs) for null before
> > dereferencing them. For instance
> > if(list_store)
> >   list_store->do_something().
> 
> After some hours of searching I found the problem.
> 
> Glib::RefPtr<Gtk::ListStore> m_refListModel;
> ...
> 
> Now I tried to clear my ListStore:
> 
> m_refListModel.clear ();
> 
> This compiled nice, but m_refListModel was NULL after calling this.
> 
> m_refListModel->clear ();
> 
> This worked as I expected. After reading the documentation of RefPtr, I
> know the problem. This was a *really* hard to find bug!

We've all made that mistake once.

I would rename the clear() method on some classes if it didn't meant
that hundreds of applications would break.

-- 
murrayc murrayc com
www.murrayc.com
www.openismus.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]