Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


#ActualPink Horror

Posted 06 October 2013 - 01:38 PM


The children are stored in a vector member of the composite: std::vector children;
So this is what the addChild method actually looks like:
 
void addChild(ComponentPtr child)
{
child->parent = this;
children.push_back(std::move(child));
}
The unique_ptr is passed by value to show that the ownership of the component is transferred to the composite.

 

In order for child to be passed in, it has to be copied, which shouldn't compile. unique_ptr is not copy constructible or copy assignable. You're moving out of a temporary unique_ptr instead of the real one.


#1Pink Horror

Posted 06 October 2013 - 01:38 PM


The children are stored in a vector member of the composite: std::vector children;
So this is what the addChild method actually looks like:
 
void addChild(ComponentPtr child)
{
child->parent = this;
children.push_back(std::move(child));
}
The unique_ptr is passed by value to show that the ownership of the component is transferred to the composite.

 

In order for child to be passed in, it has to be copied, which shouldn't compile. unique_ptr is not copy constructible or copy assignable. You'r moving out of a temporary unique_ptr instead of the real one.


PARTNERS