I wrote a function, but the compiler shouts that there are errors. But I do not know what is wrong. Look ply. It screams on line 8 and on if
std::vector<std::vector<std::shared_ptr<GameObject>>> GroupGameObjectsByMaterial(std::shared_ptr<std::vector<std::shared_ptr<GameObject>>> gameObjects) { for (std::shared_ptr<GameObject> gameObject : *gameObjects) { std::sort(*gameObjects->begin(), *gameObjects->end(), Comp); } std::vector<std::vector<std::shared_ptr<GameObject>>> gameObjectsByMaterial; gameObjectsByMaterial.reserve(gameObjects->size); for (auto it = gameObjects->begin(); it != gameObjects->end(); ++it) { if (it != gameObjectsByMaterial[gameObjectsByMaterial.size - 1]) { gameObjectsByMaterial.push_back(it); } } return gameObjectsByMaterial; } Problem lines:
if (it != gameObjectsByMaterial[gameObjectsByMaterial.size() - 1]) { gameObjectsByMaterial.push_back(*it); } Errors:
Severity Code Description Project File Line Suppression State Error C2664 'void std::vector<std::vector<std::shared_ptr<GameObject>,std::allocator<_Ty>>,std::allocator<std::vector<_Ty,std::allocator<_Ty>>>>::push_back(const std::vector<_Ty,std::allocator<_Ty>> &)': cannot convert argument 1 from 'std::shared_ptr<GameObject>' to 'std::vector<std::shared_ptr<GameObject>,std::allocator<_Ty>> &&' GameLoader Severity Code Description Project File Line Suppression State Error (active) no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=std::vector<std::shared_ptr<GameObject>, std::allocator<std::shared_ptr<GameObject>>>, _Alloc=std::allocator<std::vector<std::shared_ptr<GameObject>, std::allocator<std::shared_ptr<GameObject>>>>]" matches the argument list GameLoader Severity Code Description Project File Line Suppression State Error (active) no operator "!=" matches these operands GameLoader