I am working on a logging / tracing unit (and please don't point to existing ones, this is for the experience as much as for the result).
To get a run-time calling stack trace, the idea is to construct a TraceObject
instance first thing a function is entered, which carries the information of the current class and function. Somewhat akin to:
TraceObject to( "MyClass", "myClassFunction" );
The constructor of TraceObject
pushes this
on a per-thread stack, the destructor pops it again. The stack can thus be queried for the call stack.
I got this working to satisfaction. However, there is a small snitch: The object to
. It will, by design, never be referred to by that name. Hence, it does not need to have a name, least of all one that might collide with any identifiers used by the client (or, in case of _
prefix, the implementation).
tl;dr
Is it possible to create an anonymous, 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?