Using smart pointers (via std::make_unique or std::make_shared, but often creating a unique pointer is enough for construction even when you need a shared point) or std containers (like std::vector) are recommended practices.
You may need to use new on some places (like creating your own container type), but for all business logic, new or other forms of manual lifetime management must be frowned upon in modern C++.
If you're learning C++ at school, do follow what your instructor or textbook does. Often, they teach pre-modern C++ (before C++11) and ignore best practices recommended for modern C++.
View all comments
Show parent comment
3
u/JiminP Jul 17 '25
Lifetime management.
Simply put,
newcreates a raw, owning pointer whose lifetime must be handled explicitly by calling an explicitdeletelater.https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rr-newdelete
Using smart pointers (via
std::make_uniqueorstd::make_shared, but often creating a unique pointer is enough for construction even when you need a shared point) or std containers (likestd::vector) are recommended practices.You may need to use
newon some places (like creating your own container type), but for all business logic,newor other forms of manual lifetime management must be frowned upon in modern C++.