 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
andrew_nuss@yahoo.com Guest
|
Posted: Sat May 12, 2007 6:57 pm Post subject: easy way to get the name of a class in debug mode |
|
|
Hi,
I'm debugging a crash in my application in multi-threaded mode and for
logging I want to get the most derived name of a class instance from
within the virtual method of the base class. Is there a way to do
this?
Andy
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Seungbeom Kim Guest
|
Posted: Sat May 12, 2007 7:54 pm Post subject: Re: easy way to get the name of a class in debug mode |
|
|
andrew_nuss (AT) yahoo (DOT) com wrote:
| Quote: | Hi,
I'm debugging a crash in my application in multi-threaded mode and for
logging I want to get the most derived name of a class instance from
within the virtual method of the base class. Is there a way to do
this?
|
Yes. You could use typeid(object).name(), or supply each class
with a virtual name() function that returns its name. The former
returns an implementation-defined string, and may or may not be
enough for your logging purpose; check it. In the latter case,
don't forget to supply every class, or the function from the base
class will be silently inherited.
Note that the class has to be polymorphic, but the function itself
that uses the name doesn't have to be a virtual function.
--
Seungbeom Kim
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|