I understand slicing chops off the additional sub class-specific parts of an object, when we assign a super class to a sub class, like so:
Sub mySub;
Super mySuper = &mySub;
// mySuper DOESN'T contain any sub class behaviour
and if we did:
Sub mySub;
Super& mySuper = &mySub;
// mySuper DOES contain the sub class behaviour
but I don't understand why the reference works and why the object doesn't.
I have seen the reason is because without a reference the object needs to be copied- but I still don't see why this should result in the slicing?
I also don't understand why the reference works. We are pointing a Super reference to the beginning of a Sub object but the compiler knows how big a super object should be, so I wouldn't expect to associate the memory beyond the Super part (corresponding to the sub class component of the object) to the Super reference?