I want to create a C++ class with the following type:
- It can be declared inside of a function.
- It can be declared inside of a member function.
- It can not be declared as a class member.
The use of this: think “Root” objects for a GC.
Is this possible in C++? In particular, I’m using g++. Willing to switch to clang. Either templates or macro solution fine.
Thanks!
You could do it with a macro, perhaps:
This would only compile inside a function (because of the “do … while” bit – though you’d get a really weird error message). It seems like one of those “evil” uses of macros that you would want to avoid, however…