我有一个函数可以在此处返回对象指针的向量:
std::vector<std::shared_ptr<Object>> STile::ReadFile(const std::string filePath)
{
std::ifstream infile(workDir.Get() + filePath);
Tile tile;
std::vector<std::shared_ptr<Object>> tileObjects;
while (infile >> tile.x >> tile.y >> tile.tileID)
{
std::shared_ptr<Object> tileObject;
auto sprite = tileObject->addComponent<CSprite>();
sprite->SetTextureAllocator(&textureAllocator);
sprite->Load(workDir.Get() + "blocks.png");
sprite->SetTextureRect(0, 0, 16, 16);
tileObject->transform->setPosition(tile.x, tile.y);
tileObjects.emplace_back(tileObject);
}
return tileObjects;
}
现在我正在尝试将返回的向量分配给此处的新向量:
std::vector<std::shared_ptr<Object>> levelTiles = tileSystem.ReadFile("cord.txt");
结果是异常“抛出异常:读取访问冲突”。有什么建议吗?感谢您的帮助:)