title: how to properly destroy c++ classes with smart pointers
body: <p>I know basically delete is only required when I allocate something using new. However, I'm not certain about how to deallocate smart pointers and those classes which contain smart pointers as their members. So, how can I properly implement the destructors in the following classes?</p>
  
  <pre><code>template &lt;typename T&gt;
  class Array {
  public: 
      Array(const unsigned int length){
          T* ptr = (T*)malloc(sizeof(T)*length);
          array = std::shared_ptr&lt;T&gt;(
              new(ptr) T[length], 
              [](T* ptr){free(ptr);}
          );
      }
      ~Array(){
          // Q1 how should I properly implement this destructor?
      }
  
  private:
      std::shared_ptr&lt;T&gt; array;
  };
  
  class Example{
  public:
      Example(){
          ...
      }
      ~Example(){
          // Q2 how should I properly implement this destructor?
      }
  private:
      Array&lt;float&gt; bufferFloatArray;
      Array&lt;float&gt;* bufferFloatArrayPtr;
      std::shared_ptr&lt;float&gt; bufferFloatPtr;
  }
  </code></pre>