When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
10 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
and in m._Field, I inserted instances like following:
void Program::InsertObject(std::unique_ptr<IObject> obj, int32_t fabricSize)
{
CellCoord coord = {
static_cast<int32_t>(obj->getPos().x / fabricSize),
static_cast<int32_t>(obj->getPos().y / fabricSize)};
m._Field[coord].push_back(std::move(obj));
}
// ...
m._Field.clear();
for (auto &hive : m._World.getHives())
{
InsertObject(std::make_unique<Hive>(hive), m._FabricSize);
}
for (auto &ant : m._World.getAnts())
{
InsertObject(std::make_unique<Ant>(ant), m._FabricSize);
}
and here is a problem;
with line:
InsertObject(std::make_unique<Ant>(ant), m._FabricSize);
it creates completely new, distinct instance of Ant that is different from what .getAnts() gives as I believe. and this causes first snippet to not work.
but the problem is, I'm not sure how to modify my code to make it work. any ideas?
You're triggering the copy constructor of ant
It doesn't make sense to create a unique ptr to something that is owned by the vector
So I'm not really sure what you're trying to do or expect to be happening
huh
problem solved by changing vectors in World class from std::vector<Object> to std::vector<std::shared_ptr<Object>>
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity