This just jumped into my head and I can't figure it out.
If I have a code like this:
struct A { char x[100]; };
struct B { int data; };
struct C : A, B {};
#include <iostream>
using namespace std;
B* get_me_some_stuff()
{
static int x = 0;
if (++x % 2 == 0)
return new B();
else
return new C();
}
int main()
{
B* x = get_me_some_stuff();
B* y = get_me_some_stuff();
x->data = 10;
y->data = 20;
cout << x->data << " " << y->data << endl;
return 0;
}
How does the compiler determine the memory location of the data
member?