title: std::shared_ptr in a union
body: <p>I'm implementing a "variant" class which must have the smallest possible memory footprint and store some objects with a shared pointer mechanism.</p>
  
  <p>For this, I would like to make a union within the class of all variable types. This includes some shared_ptr's.</p>
  
  <p>The operator= and copy constructors must change the data type of the variant, hence switching to another member in the union. Upon switching to a shared_ptr, this one should be reset to null without deleting/deowning the pointer. Is there a way to do this?</p>
  
  <p>Of course, there would be other ways to implement this but they are generally more complex, less safe or more memory consuming in my case. Any suggestion welcome though.</p>
  
  <p>Thanks!</p>