|
Boost Users : |
Subject: Re: [Boost-users] enabled_shared_from_this: bad_weak_ptr exception + online doc explanation
From: Igor R (boost.lists_at_[hidden])
Date: 2008-09-06 15:10:10
> 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 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