i think the memory manager needs to know which kind of object you are going to point to with this pointer
It doesn't need to you can cast it. But the problem is that it can cause problems when you use it. Some of the common ones can be metadata mismatch (rare), or just the dereference won't work the way you want it to. Test obj; // created an object Test *pt = &obj; // store the pointer NewTest *nt = (*NewTest)pt; // But now NewTest functions aren't present on the object you can easily shoot yourself in the foot // Also the cast doesn't always works properly
It doesn't need to.. C has void pointers doesn't it? The requirements is strict in C++ to ensure type safety.
Обсуждают сегодня