5,321
edits
Line 144: | Line 144: | ||
// Block-scope car | // Block-scope car | ||
Car my_car; | Car my_car; | ||
// Old C++ | // Old C++ | ||
// Must call delete my_car; to avoid memory leaks. | // Must call delete my_car; to avoid memory leaks. | ||
Car *my_car = new Car(); | Car *my_car = new Car(); | ||
// Using unique ptr | // Using unique ptr | ||
std::unique_ptr<Car> my_car(new Car()); | std::unique_ptr<Car> my_car(new Car()); | ||
// Or starting from C++14 | // Or starting from C++14 | ||
auto my_car = std::make_unique<Car>(); | auto my_car = std::make_unique<Car>(); |