The problem is that the objects Toy()are being passed in boost::assign::list_of(). These are temporary objects that are created on the stack before being copied to the object Box(which will be on the heap)
to avoid creating them on the stack, you can do this:
Box() : m_toys()
{
Toy* t = new Toy;
for (int i = 0; i < 3; ++i)
m_toys.push_back(*t);
delete t;
}
source
share