diff --git a/src/bitmap_type.h b/src/bitmap_type.h index 75f9ab6642..3aff869724 100644 --- a/src/bitmap_type.h +++ b/src/bitmap_type.h @@ -126,9 +126,9 @@ public: return *this; } - virtual TileIterator *Clone() const + virtual std::unique_ptr Clone() const { - return new BitmapTileIterator(*this); + return std::make_unique(*this); } }; diff --git a/src/newgrf_airport.h b/src/newgrf_airport.h index 264da05ebb..2774fbc645 100644 --- a/src/newgrf_airport.h +++ b/src/newgrf_airport.h @@ -58,9 +58,9 @@ public: return this->att->gfx; } - virtual AirportTileTableIterator *Clone() const + virtual std::unique_ptr Clone() const { - return new AirportTileTableIterator(*this); + return std::make_unique(*this); } }; diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 94b4423a15..dbfc00494a 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -2400,7 +2400,7 @@ CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_s CommandCost error = CommandCost((rtt == RTT_TRAM) ? STR_ERROR_NO_SUITABLE_TRAMWAY : STR_ERROR_NO_SUITABLE_ROAD); // by default, there is no road to convert. bool found_convertible_road = false; // whether we actually did convert any road/tram (see bug #7633) - TileIterator *iter = new OrthogonalTileIterator(area_start, area_end); + std::unique_ptr iter = std::make_unique(area_start, area_end); for (; (tile = *iter) != INVALID_TILE; ++(*iter)) { /* Is road present on tile? */ if (!MayHaveRoad(tile)) continue; @@ -2556,7 +2556,6 @@ CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_s } } - delete iter; return found_convertible_road ? cost : error; } diff --git a/src/station_base.h b/src/station_base.h index ebb29026a9..e8eb40d4b8 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -555,9 +555,9 @@ public: return *this; } - virtual TileIterator *Clone() const + virtual std::unique_ptr Clone() const { - return new AirportTileIterator(*this); + return std::make_unique(*this); } }; diff --git a/src/tilearea_type.h b/src/tilearea_type.h index 2484aac2c6..412f7c3752 100644 --- a/src/tilearea_type.h +++ b/src/tilearea_type.h @@ -146,7 +146,7 @@ public: /** * Allocate a new iterator that is a copy of this one. */ - virtual TileIterator *Clone() const = 0; + virtual std::unique_ptr Clone() const = 0; /** * Equality comparison. @@ -225,9 +225,9 @@ public: return *this; } - virtual TileIterator *Clone() const + virtual std::unique_ptr Clone() const { - return new OrthogonalTileIterator(*this); + return std::make_unique(*this); } }; @@ -264,9 +264,9 @@ public: TileIterator& operator ++(); - virtual TileIterator *Clone() const + virtual std::unique_ptr Clone() const { - return new DiagonalTileIterator(*this); + return std::make_unique(*this); } };