I already know that it's not possible to print the name of a variable, neither in C or in C++, this is mentioned in other StackOverflow posts.
However I know that in other languages, like Delphi, it is possible to print the classname of an object. I have no idea if this is possible in C++.
Hence my question: is it possible to print the objectname of an object?
Some background: I am writing a program which is using STL vectors to keep track of locations and values (both in separate vectors), and I'd like to print the content of the vectors, preceeded by the object name (so that I can see if I'm looking at locations or if I'm looking at values).
You can use:
typeid(someObject).name();
But the return value is implementation-defined and isn't required to return anything useful or readable at all.
Returns an implementation defined null-terminated character string containing the name of the type. No guarantees are given, in particular, the returned string can be identical for several types and change between invocations of the same program.
So if you need it for more than just logging then I'd suggest to just keep track of them yourself.
More info on .name()
.