title: Returning pointers to heap objects without smart pointers
body: <p>I have an abstract class, IPacket.</p>
  
  <pre><code>/*
   * Represents an abstract network packet.
   */
  class IPacket
  {
  
  public:
  
      virtual void read(...) = 0;
  
      virtual void write(...) = 0;
  
      virtual int getID() const = 0;
  };
  </code></pre>
  
  <p>And I'd like to (and have been) returning a pointer to like so:</p>
  
  <pre><code>class PacketMedium
  {
      /*!
       * Returns a pointer to the next pending packet or NULL if there are no packets pending.
       * \note The object must deleted when you are finished with it.
       */
      IPacket* receivePacket();
  };
  </code></pre>
  
  <p>Now obviously, this is bad practice; requiring the caller to delete a pointer that wasn't even allocated by itself. The convention I believe, is to use smart pointers, i.e.</p>
  
  <pre><code>class PacketMedium
  {
  public:
  
      std::unique_ptr&lt;IPacket*&gt; receivePacket();
  };
  </code></pre>
  
  <p>But as this is library code, smart pointers are a nono, notwithstanding the fact I'd prefer to avoid them regardless.</p>
  
  <p>What would my best option be?</p>
  
  <p>Thanks for any help :)</p>
  
  <p>EDIT: this has been asked before and very good answers were given, although they all suggest smart pointers, or just not allocating on the heap. Given that <code>IPacket</code> is abstract, stack allocation wouldn't work.</p>