There is a class containing a container of objects (ships). I want through the class method to change the property of a single object. The method itself returns bool (a sign that the object is found or not), and I want to return the object itself (attention) through the method parameter.
Problem - my FindShip object is deleted when exiting the method. How to make it continue to live?
void SeaGame::PlayerShoot(const Point& In) { Ship FindShip; //создаю временный объект, который нужно изменить if (!ComputerField->FindShipByPoint(In,FindShip)) return; //что-то делаем с объектом FindShip.setDeckByPoint(In, true); } //метод //Result - должен возвращать искомый объект bool FindShipByPoint(const Point& p, Ship& Result) const { for (Ship ship: _ships) //_ships - котейнер stl { for (Point _p : ship.getPoints()) if (p == _p) //реализован соответствующий operator { Result = ship; //реализовано operator= (копирующее присваивание) return true; } } return false; } Do I need to do rvalue links here? Or are they nothing to do with?
PlayerShootmethod and save. The semantics of moving here has nothing to do with it. Just at the end of the scope, the object is destroyed ... - HarryPlayerShoot? - Harry