vendredi 25 juin 2021

C++: Assigning derived class pointer to base class pointer

Not very familiar with C++, so apologies for the potentially nooby question (though, I couldn't find an answer to this, despite semi-similar questions).

In a codebase I'm working on (sorry, can't share exact code), there's a Base class and a Derived class. I have a pointer to the derived class, d.

At some point, I set

Base* b = d;

What's super weird is that the pointers end up with different values! b ends up with an address exactly 8 greater than what d was.

I couldn't repro this with a straight-forward Base/Derived class, so I'm convinced there's something being done in the particular classes I'm working with.

Can anyone shed some light on how this can be possible? What in C++ might allow for something like this?

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire