|
Boost Users : |
Subject: Re: [Boost-users] enabled_shared_from_this: bad_weak_ptr exception + online doc explanation
From: cxv_at_[hidden]
Date: 2008-09-12 14:51:20
Thanks for the reply. But I am still unsure where I should invoke this
static method.
1) I need the member variables initialized...and if I cant do it in the
constructor, then where should I?
2) Also, your sample code does not use shared_from_this() ... I would like
to learn how to correctly use shared_from_this() because I'll be using it in
other places in my code too.
Thanks,
/C.
2008/9/6 Igor R <boost.lists_at_[hidden]>
> > TextTool::TextTool(QDialog *taskDialogue) : Tool(this->name)
> > {
> > boost::shared_ptr<TextTool> pointerToThis =
> > TextTool::shared_from_this(); //ERROR OCCURS ON THIS LINE
> >
> > bold = boost::shared_ptr<ToggleControl>(new
> > ToggleControl(pointerToThis));
> > }
>
>
> You cannot call shared_from_this in the constructor. Instead, you can
> define a static constructing method, like this:
>
> // untested!!
> static boost::shared_ptr<TextTool> TextTool::create(QDialog *taskDialogue)
> {
> boost::shared_ptr<TextTool> pointerToThis(new TextTool(taskDialogue));
> pointerToThis->bold.reset(new ToggleControl(pointerToThis));
> return pointerToThis;
> }
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net