'Base pointer offset adjustment for multiple inheritance question

I know base offset adjustment will happen in this situation

class Mother {
 public:
  virtual void MotherMethod() {}
  int mother_data;
};

class Father {
 public:
  virtual void FatherMethod() {}
  int father_data;
};

class Child : public Mother, public Father {
 public:
  virtual void ChildMethod() {}
  int child_data;
};
Father *f = new Child;

During compilation, this code is equivalent to

Child *tmp = new Child;
Father *f = tmp ? tmp + sizeof(Mother) : 0;

My question is how this offset is determined in the compilation phase? for example, in the following case

void fun(Father* f) {
    // do something
}

we don't know what object the pointer will receive, how is it possible to determine whether or how much offset adjustment is needed during compilation.

I hope someone can answer my doubts, Thank you very much!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source