Anonymous objects on the stack, in C++?
<p>I am working on a logging / tracing unit (and please <strong>don't</strong> point to existing ones, this is for the experience as much as for the result).</p>

<p>To get a run-time calling stack trace, the idea is to construct a <code>TraceObject</code> instance first thing a function is entered, which carries the information of the current class and function. Somewhat akin to:</p>

<pre><code>TraceObject to( "MyClass", "myClassFunction" );
</code></pre>

<p>The constructor of <code>TraceObject</code> pushes <code>this</code> on a per-thread stack, the destructor pops it again. The stack can thus be queried for the call stack.</p>

<p>I got this working to satisfaction. However, there is a small snitch: The object <code>to</code>. It will, by design, <em>never</em> be referred to by that name. Hence, it does not need to <em>have</em> a name, least of all one that might collide with any identifiers used by the client (or, in case of <code>_</code> prefix, the implementation).</p>

<p><strong>tl;dr</strong></p>

<p>Is it possible to create an <em>anonymous</em>, non-temporary object on the stack (i.e. one that will live until the function returns, but doesn't have an identifier), and if yes, how would it be done?</p>
