I wrote the following bit of code. Although it compiles, i'm not quite understanding what actually happens when i execute: Base MyBase = MyDerived;
How does it actually come to be that this line passes the value assigned to the base class of MyDerived into my new "MyBase" class?
When you assign Derived to Base, what's actually happening is that the derived class is being implicitly cast to the base class. i.e. you're losing all derived data and any called to an overridden method will be invoked on the base class. Base MyBase = MyDerived;
What you're looking for is this: Base* MyBase = &MyDerived;
MyBase is now a pointer to the class, meaning that method calls on overridden methods will be invoked on the derived class.