Avatar ·

Why experienced C++ developers advise avoiding the use of `new`

Hi! I'm transitioning from Java to C++ and I'm having some confusion. In Java, we constantly use `new` to create objects—it's standard practice. But reading forums and articles, I see that many experienced C++ developers advise "minimizing the use of `new`." Honestly, this sounds strange. Here's an example I wrote, following my Java habits: ```cpp #include #include class Person { public: Person(const std::string& name) : name_(name) {} void greet() const { std::cout << "Hello, I'm " << name_ << std::endl; } private: std::string name_; }; int main() { Person* p = new Person("Alice"); p->greet(); // Forgot delete? Or do I need to call it somewhere? Person* p2 = new Person("Bob"); p2->greet(); // And if