auto cc = std::shared_ptr<Customer>(new Customer(customer));
(the only difference is that make_shared might be more efficient because it can do a single memory allocation and store the reference counters together with the object)
In other words, it creates a heap allocated copy of customer.
Note: std::make_shared<T>() creates a new heap-allocated instance of T, and wraps the pointer in a std::shared_ptr<T>.
This invokes the copy-constructor, creating a new (heap-allocated) copy of your local (stack-allocated) object:
1 2 3
Customer customer = { 0, "John Doe", "johndoe@example.com" };
auto cc = std::make_shared<Customer>(customer);
cc = nullptr; /* Destroys the heap-allocated copy owned by 'cc', the original 'customer' is uneffected */
You can avoid the copy and instead create the object directly on the heap:
1 2
// Customer customer = { 0, "John Doe", "johndoe@example.com" };
auto cc = std::make_shared<Customer>(0, "John Doe", "johndoe@example.com");
This wraps the pointer to the local (stack-allocated) object in the std::shared_ptr<T>, which will obviously cause trouble:
1 2 3
Customer customer = { 0, "John Doe", "johndoe@example.com" };
auto cc = std::shared_ptr<Customer>(&customer);
cc = nullptr; /* Whoops: This will attempt to delete the local (stack-allocated) object !!! */