How to make it clear when an object does not exist in C++?
<p>I have a class which depending on the state of the application and user options may not always be able to exist in any meaningful state.</p>

<p>What is the best way to make it clear when the object does not exist?</p>

<p>Two ideas I've thought of so far and why I don't believe they are not the answer:</p>

<ol>
<li>A smart pointer set to NULL when the object doesn't exist, this sends a clear message that there is no object here, however I've read that dynamic memory allocation using 'new' should be the exception not the rule in C++ and it also prevents me being able to pass in by reference to other functions (since the pointer may not always point to an object).</li>
<li>A boolean flag in the object which, when set, causes any methods called to throw an exception. This would require checks in every method and feels like a kludge. I also believe the best practice is that <a href="http://www.bennadel.com/blog/1382-Hal-Helms-On-Object-Oriented-Programming-Day-Four.htm" rel="nofollow">all objects that exist should be valid</a>  and we shouldn't need to call a validate (or similar) function because the existence of the object implies it's already valid and ready to have its methods called.</li>
</ol>
