![]() |
[C++] Class names
is there a possibility to get the name of a class from one of its base classes without much effort ? would be nice if it'd be somewhat standardized stuff :D
|
Re: [C++] Class names
Use dynamic_cast?
|
Re: [C++] Class names
I am not sure quite what you mean, but you could have a private variable that is modified to the class's name in the class's constructor. You could also make a global constant value and just set the string to use it.
|
Re: [C++] Class names
dynamic cast would cast it, yes, but I want the name of it.
I could of course create a virtual function returning the name, or a member variable being updated. that could of course be optimized by some preprocessor stuff to have less to write. but that's all stuff i'd call too much effort :) |
Re: [C++] Class names
Quote:
Although I'm not sure if it will work on base classes... I think the best way is(like sfx1999 said) to make a way to 'identify' each class, since dynamic_cast isn't very efficient I believe. |
Re: [C++] Class names
Code:
char g_mainclassname[] = "mainclass"; |
Re: [C++] Class names
you can also use #define to avoid typing the get class name function for each class:
http://cvs.sourceforge.net/viewcvs.p....1&view=markup |
Re: [C++] Class names
Whistler, I think what he means is that he wants the base class to be able to find out what the derived class is. Like this:
Code:
CBaseClass *instance = new CDerivedClass; |
Re: [C++] Class names
I just realized something. My method might not work either. The main class's constructor might override the derived one's. You would need a hack to check if the value was set.
|
Re: [C++] Class names
Quote:
|
All times are GMT +2. The time now is 06:38. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.