title: What is the lifecycle of a C++ object?
body: <p>I'm a seasoned C developer who is just now getting into C++, and I must admit, I'm very confused about how many ways there are to create, retain, and destroy C++ objects. In C, life is simple: assignment with <code>=</code> copies on the stack, and <code>malloc</code>/<code>free</code> manage data on the heap. C++ is far from that, or so it seems to me.</p>
  
  <p>In light of that, here are my questions:</p>
  
  <ol>
  <li>What are <em>all</em> the ways to create a C++ object? Direct/copy constructor, assignment, etc. How do they work?</li>
  <li>What are all the different initialization syntaxes associated with all these types of object creation? What's the difference between <code>T f = x</code>, <code>T f(x);</code>, <code>T f{x};</code>, etc.?</li>
  <li>Most importantly, <em>when</em> is it correct to copy/assign/whatever <code>=</code> is in C++, and when do you want to use pointers? In C, I got very used to throwing pointers around a <em>lot</em>, because pointer assignment is cheap but struct copying is less so. How do C++'s copy semantics affect this?</li>
  <li>Finally, what are all these things like <code>shared_ptr</code>, <code>weak_ptr</code>, etc.?</li>
  </ol>
  
  <p>I'm sorry if this is a somewhat broad question, but I'm very confused about when to use what (not even mentioning my confusion about memory management in collections and the <code>new</code> operator), and I feel like everything I knew about C memory management breaks down in C++. Is that true, or is my mental model just wrong?</p>
  
  <p>To sum things up: how are C++ objects created, initialized, and destroyed, and when should I use each method?</p>