Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

gimp

Automatic Class Names

This topic is 5240 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Currently I have a CObject base class. It encomapsses: -The ability to become a heirachy(parent\child pointers\cleanup) -The classes name. Currently the name is just set by a user class like this: CObject::SetName("Model"); ...in the users constructor. That kinda sucks doesn''t it. I should have an object register that just links the object against a string name on creation. Besides that every time I create a new class I have to remember to change the user class name. I''d love to use __CLASS__ but that doesn''t exist... Any idea''s?

Share this post


Link to post
Share on other sites
Advertisement
well if descending into the hell of preprocessor macros doesn''t bother you, you could define a macro like this...


#define DEF_CLASS(className) \
class className \
{ \
virtual std::string getClassName() { return #className; };\



then call define getClassName as a pure virtual in your base class and call it from the base constructor.

That solves your initial problem, but it makes your code pretty ugly and brings all the evil problems the macros always do.

Share this post


Link to post
Share on other sites
If you have RTTI enabled for your project, you can probably just use typeid() on your classes and get at the name via std::type_info::name().

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!