Jump to content

  • Log In with Google      Sign In   
  • Create Account


#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