Bool- if a pointer points to a certain class?

In an if statement, how would you check to see if a pointer to an abstract class points to one of its derived classes?
Use dynamic_cast. The pointer returned would be NULL/0 if the pointer you provided does not point to the specified derived class. Otherwise, it returns a usable pointer to the derived class.
Normally you should never have to do that because you have virtual functions to get different behaviour for different types.

But if you really want to do it you can use dynamic_cast.
What's dynamic_cast? I've heard of it before, but I'm not sure what it does or how to use it.
Anyone?
Is Google not working anymore? It would be the second time today. :-P
Last edited on
I tried, but it confused the crap out of me O_o I'm just not sure how to use it...

dynamic_cast i mean, not google lol xD
Last edited on
Well, you have been given the technical side by shacktar, meaning you now know how it is used, and you know (because these people told you) that it resolves the problem you have, which is finding out if a pointer points to a specific derived class. So I bet you can conclude stuff from this: The dynamic_cast operator can tell you if the class pointed by a base pointer is of a specific derived class or not. So what is it? An operator that can downcast a pointer safely. Are you saying that you need to know more? Want to know how it works more thoroughly? Then read about RTTI: Run-Time Type Information.

But I must warn you: If you found formal documentation confusing, this will hardly be any different. So maybe you would like to take it slow, get more used to the language and stuff before you dig into the beast's entrails. Just sayin'!

Good luck.
Last edited on
Topic archived. No new replies allowed.