Open DanRStevens opened 4 years ago
Generally in agreement here. There are cases where pointers make sense but I'm somewhat unfamiliar with so-called smart pointers. Seems now is as good a time as any to start moving the code in that direction.
Did a quick scan of the code to see where we have naked new
:
State
Structure
derived typesMine
typeTileMap
ProductListBoxItem
Utility
Additionally, our choice of some external code forces some uses of new
on us:
XmlElement
objects)I do want to move away from TinyXML and reimplement with json. I've had a lot of success with https://github.com/nlohmann/json for json parsing, it feels very natural in C++.
Micropather we may want to consider adjusting to use without raw memory management. Might make sense to fork it for our purposes as the library really doesn't change much if at all or pull it out of the OPHD repository and add it as a submodule from its original source: https://github.com/leethomason/MicroPather
I think I added the code in before I really understood how to use git submodules :/
The project has many occurrences of
new
anddelete
. These are best avoided in modern C++ code. Many of these (possibly all) can likely be replaced bystd::unique_ptr
. As a bonus, usingstd::unique_ptr
may make some destructors empty, allowing us to omit them.Reference: C.149: Use unique_ptr or shared_ptr to avoid forgetting to delete objects created using new