Sign in to follow this  

dynamic_cast fails

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

So my c++ project is showing some strange behavior.

dyanamic_cast returns null when the type I want it to cast to is definately the right type. I attached a screen shot showing this.

The vtable says RuntimeProperty and that is exactly what I want to cast this to and yet it fails.

I testing dyanmic_cast the line after the object was created and it worked fine but later on it fails.

The problem may be related to the fact that the object is allocated on a custom garbage collected heap.

Does anybody have any insight as to why dyamic_cast would fail even though I can plainly see that the object types match?

Share this post


Link to post
Share on other sites
I suspect the object memory is corrupt?
Instead of dynamic cast, can you static cast it for a test and check if the object is still valid?

Share this post


Link to post
Share on other sites
dynamic_cast works right after the object is created,

and as a temporary work around I added another virtual method to get the class type as an enumerated type and check the class type using that. Using the enumerated type for type checking joined with a static cast it works fine. It doesn't appear that the block is memory is corrupted. All of the values, including the vtable, are the same as when the object is first initialized. Edited by HappyCoder

Share this post


Link to post
Share on other sites
The workaround is likely to be hiding the true problem.

Can you simmer it down to a very small test case? As you rip out code, pay close attention to the point where it begins to work and the differences from the previous iteration. If on the other hand it never works, it means you're doing something incorrectly, in which case the sample will highlight to those here what the misunderstanding might be. Edited by e?dd

Share this post


Link to post
Share on other sites

This topic is 1964 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this