How to prevent an object from being deleted in places where it shouldn't, at compile-time?
<p>I have classes <code>Graph</code> and <code>Algorithm</code>:</p>

<pre><code>class Graph
{
...
};

class Algorithm
{
...
private:
Graph * mGraph;
...
};
</code></pre>

<p>I want my algorithm to be able to do everything with <code>mGraph</code> except deleting it. I.e. I want to detect (at compile time) if somewhere in algorithm I'm deleting the graph. Is there a good (elegant) way to do such a thing? (The only way I realized is making <code>Graph</code>s destructor private so only friend classes have permission to delete it)</p>
