Class B
{};
Class Derived : Public B
{int a[1000];
};
int main()
{ Base b;
Derived*Dptr=static_cast<Derived*>(&b)
....
...some code
....
}
Here i typecasted Base address into derived and derived occupies more memory than base(1000*2 extra here).So how this memory is being adjusted when typecasting happens.
Earlier same address(&b) could have reserved 1 byte as Base is an empty class,Now that it is turned into Derived ,doesnt it have to reserve extra space to accomadate these 1000 ints at this address ?Wont memory get corrupted if this happens?