Sharing ownership over a dynamic array
<p>I have a container class which receives a pointer to a dynamic array from a c api. This class then becomes the owner of the buffer and must delete it using delete[]. </p>

<p>So this buffer might have been created as follows:</p>

<p>Value*ptr = malloc(10 * sizeof(Value));</p>

<p>I also have a class called ValueWrapper which operates on a single Value. </p>

<p>My container has a getter which returns ValueWrapper objects, something like this:</p>

<pre><code>ValueWrapper Container::valueWrapper(int index)
{
    return ValueWrapper(_value[index]);
}
</code></pre>

<p>However, objects of type VWrapper will have an invalid Value* once my container is destroyed.</p>

<p>How can I deal with this problem? I need to share ownership of Value*'s in some way. Would it be reasonable to insist that ValueWrapper objects can only be used when the Container is in scope and write this in the comment for Container::valueWrapper(int index)?</p>
