Loss of RTTI information after returning from a function

Given the class and subclass:

class Event {...} class Note : public Event {...} 

The note is cloned and stored in the pointer inside the f () function. Typical information is stored in a pointer and can be restored by dynamic_cast:

 void f() { pEvent = pNote->Clone(); // create a clone of a Note ASSERT(dynamic_cast<Note*>(pEvent)); // check the pointer, here it works } 

Now, after returning from f (), type information is lost:

 f(); ASSERT(dynamic_cast<Note*>(pEvent)); // -> "Access violation - no RTTI-data" 

VS-debugger shows the actual value of the pointer (unchanged), but not a derived class, except that it is in f() -scope.

How to lose RTTI-info for a pointer when returning from a function?

+4
source share
1 answer

There was a destructor accidentally harming the pointer. After removing this error, RTTI works as expected.

+5
source

Source: https://habr.com/ru/post/1369629/


All Articles