sajty/ember — comment on commit 6a30ef9cba35617598ec84978df32966e2af17b9
File:  line 0
By sajty:

I think you get it wrong how things work.
When a class is allocated, its allocating all inherited classes too in a row.
If you cast it to a subclass it will just ADD the offset and returns it, except if its the first parent, because the first parent has the same pointer.
if you cast it in other direction it will negate the offset.
but in this case its not the first.
So static_cast is doing this behind the scenes, when there are multiple parents of a class.
Other fix would be to change the order of the parents on the class declaration.

Here is an example:

```

#include
class A {
public:
int a;
};
class B{
public:
int b;
};
class C : public A, public B
{
public:
int c;
};
int main(){
C c;
c.a=2;
c.b=3;
c.c=5;
B* b = static_cast((void*)&c);
std::cout << b->b << std::endl;
std::cout << (int)b << std::endl;

b = static_cast(&c);
std::cout << b->b << std::endl;
std::cout << (int)b << std::endl;

}
```

output:

```
2
1768272
3
1768276
```