Is there a __CLASS__
macro in C++ which gives the class name similar to __FUNCTION__
macro which gives the function name
views:
1330answers:
4
+5
A:
The closest thing there's is to call typeid(your_class).name()
- but this produces compiler specific mangled name.
To use it inside class just typeid(*this).name()
Aleksei Potov
2009-11-03 11:44:30
Thanks.. this is good enough for logging
mortal
2009-11-03 11:47:40
You have to know your class first to invoke this ;-)
Michael Krelin - hacker
2009-11-03 11:48:18
this is for logging, so I do know the class where I am invoking this. Just trying to avoid explicitly defining a char array containing the class name
mortal
2009-11-03 11:51:54
typeid(*this).name() can be used inside class functions
Aleksei Potov
2009-11-03 11:55:36
That's better. As for knowing the class, defining char array sounds better than postponing it till runtime.
Michael Krelin - hacker
2009-11-03 12:21:12
That's a pity it isn't defined like __ CLASS __ , it can be handy at preprocessor stage! :(
kexik
2010-08-23 11:51:57
+2
A:
Not yet. (I think __class__
is proposed somewhere). You can also try to extract class part from __PRETTY_FUNCTION__
.
Michael Krelin - hacker
2009-11-03 11:46:57
A:
If you're talking MS C++ (You should state, esp as __FUNCTION__
is a non-standard extension), there are __FUNCDNAME__
and __FUNCSIG__
symbols which you could parse
Ruben Bartelink
2009-11-03 11:48:07
A:
If your compiler happens to be g++
and you are asking for __CLASS__
because you want a way to get the current method name including the class, __PRETTY_FUNCTION__
should help (according to info gcc
, section 5.43 Function Names as Strings).
ndim
2009-11-03 11:52:21