title: Why not to inherit from std::allocator
body: <p>I created my own allocator like so:</p>
  
  <pre><code>template&lt;typename T&gt;
  class BasicAllocator
  {
      public:
          typedef size_t size_type;
          typedef ptrdiff_t difference_type;
          typedef T* pointer;
          typedef const T* const_pointer;
          typedef T&amp; reference;
          typedef const T&amp; const_reference;
          typedef T value_type;
  
  
          BasicAllocator() throw() {};
          BasicAllocator (const BasicAllocator&amp; other) throw() {};
  
          template&lt;typename U&gt;
          BasicAllocator (const BasicAllocator&lt;U&gt;&amp; other) throw() {};
  
          template&lt;typename U&gt;
          BasicAllocator&amp; operator = (const BasicAllocator&lt;U&gt;&amp; other) {return *this;}
          BasicAllocator&lt;T&gt;&amp; operator = (const BasicAllocator&amp; other) {return *this;}
          ~BasicAllocator() {}
  
          pointer address (reference value) const {return &amp;value;}
          const_pointer address (const_reference value) const {return &amp;value;}
  
          pointer allocate (size_type n, const void* hint = 0) {return static_cast&lt;pointer&gt; (::operator new (n * sizeof (value_type) ) );}
          void deallocate (void* ptr, size_type n) {::operator delete (static_cast&lt;T*&gt; (ptr) );}
  
          template&lt;typename U, typename... Args&gt;
          void construct (U* ptr, Args&amp;&amp;  ... args) {::new (static_cast&lt;void*&gt; (ptr) ) U (std::forward&lt;Args&gt; (args)...);}
          void construct (pointer ptr, const T&amp; val) {new (static_cast&lt;T*&gt; (ptr) ) T (val);}
  
          template&lt;typename U&gt;
          void destroy (U* ptr) {ptr-&gt;~U();}
          void destroy (pointer ptr) {ptr-&gt;~T();}
  
          size_type max_size() const {return std::numeric_limits&lt;std::size_t&gt;::max() / sizeof (T);} /**return std::size_t(-1);**/
  
          template&lt;typename U&gt;
          struct rebind
          {
              typedef BasicAllocator&lt;U&gt; other;
          };
  };
  </code></pre>
  
  <p>But I want to know why I should never inherit from <code>std::allocator</code>. Is it because it doesn't have a virtual destructor? I've seen many posts saying that one should create their own and not inherit. I understand why we shouldn't inherit <code>std::string</code> and <code>std::vector</code> but what is wrong with inheriting <code>std::allocator</code>?</p>
  
  <p>Can I inherit my class above? Or do I need a virtual destructor to do that?</p>
  
  <p>Why?</p>