you convinced me on the first.
about the second, I'm just thinking logically:
usually , the compiler breaks down a class to C-struct + the methods that are now global and also accepts 'this' pointer.
so
Code:
class Car{
int dist;
drive();
};
becomes (after processing)
Code:
struct Car{
int dist;
}
drive(Car* this);
now, B doesn't add any size to A , and anyway, B is driven from A, so you can upcast B* to A*,
so eventually , what you get is
Code:
void print (B* this){
std::cout<<((A*)this))->x;
}
which is not so bad, because B is in fact A. the only problem that may arise is with the static_cast (or reinterprect_cast). so we're downcasting only to up-cast later, and anyway, the memory address stays the same..