tags:

views:

1330

answers:

4

Is there a __CLASS__ macro in C++ which gives the class name similar to __FUNCTION__ macro which gives the function name

+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
Thanks.. this is good enough for logging
mortal
You have to know your class first to invoke this ;-)
Michael Krelin - hacker
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
typeid(*this).name() can be used inside class functions
Aleksei Potov
That's better. As for knowing the class, defining char array sounds better than postponing it till runtime.
Michael Krelin - hacker
That's a pity it isn't defined like __ CLASS __ , it can be handy at preprocessor stage! :(
kexik
+2  A: 

Not yet. (I think __class__ is proposed somewhere). You can also try to extract class part from __PRETTY_FUNCTION__.

Michael Krelin - hacker
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
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