Advertisement Jump to content
Sign in to follow this  
Preacher

instanceof functionality c++

This topic is 4934 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

Hi just moving over to c++ from java and trying to design a flexable event handler for a basic game engine. I know that c++ does not have an "instanceof" operator but is there a method to check the specifc type of class a pointer points to or do i have to implent a system myself???

Share this post


Link to post
Share on other sites
Advertisement
You can build your own RTTI system by adding to each class a pointer to the parent class so that you can check if a class was derived from another class and so if dynamic casting is possbile.

Share this post


Link to post
Share on other sites
Quote:
Original post by dali
You can build your own RTTI system by adding to each class a pointer to the parent class so that you can check if a class was derived from another class and so if dynamic casting is possbile.


That's probably insanly stupid since the language already offer functionality for it and any self-made solutions is likely to turn out as an error prone maintenence nightmare.

Share this post


Link to post
Share on other sites
Ok thanks will give the Visitor pattern a look, for what i want i think ill just keep a number of lists of differnet objects instead of one multi type list (which just sounds bad anyway:)) thanks all

Share this post


Link to post
Share on other sites
i ghettoed a solution to that. just give your objects a name() or toString() method. make the name or toString return a char*, which is the name of the class, thats what i do.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!