I was playing around with a bunch of casting operators a while ago, which apparently I did not really get at the time. I was looking over my code now and I saw this:
Base(Derived &p_derived) : m_state(static_cast<Base>(p_derived).m_state){}
I think I have now got a better understanding of casting of pointers and references thanks to a very good answer here on stackoverflow, but now there's objects involved. What exactly happens when the reference is casted to an object? Or what if p_derived was the object itself and not just a reference? Would it be creating new objects and if so, how would these be instanciated?
I'm also surprised that this could be compiled at all since in Base.h, where this code is found, Derived is only forward declared meaning it shouldn't know that it actually derives from Base. I tried at another place to do a static cast from a Derived* to a Base*, but that would rightfully not compile due to the types being incompatible as far as that translation unit was concerned.