Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class name macro [duplicate]

Tags:

c++

class

macros

Possible Duplicate:
CLASS macro in C++

Hello, are there any ways to get name of class with macro like __FUNCTION__ for function name? The only ideas I have is inheriting some base class with pure virtual toString and define the names by hands eash time. Thanks.

like image 597
Max Frai Avatar asked May 14 '26 16:05

Max Frai


2 Answers

It depends what exactly is the context. A rough equivalent to get the implementation defined internal name of the class could be to use typeid operator as shown. Note that the output is implementation defined.

typeid(yourclass).name()

like image 128
Chubsdad Avatar answered May 17 '26 09:05

Chubsdad


Easiest is probably (to define a macro) calling some function to derive the class name from __FUNCTION__ (or __PRETTY_FUNCTION__ for GCC, or maybe even __FILE__).

like image 22
Michel de Ruiter Avatar answered May 17 '26 07:05

Michel de Ruiter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!