The Grand Ayatollah Makarem Shirazi answered a question about the way the foetus can inherit.
Question: If a man dies whilst his wife is pregnant, can the foetus inherit?
The Grand Ayatollah Makarem: Whenever there is a child in the mother’s stomach from the deceased, and there are other inheritors in that level like children, and father and mother, at the time of dividing the inheritance, the shares of two sons must be put aside for the child in mother’s stomach. When the child is born alive, is entitled to inheritance and if for example it is a boy or a girl, the extra inheritance will be divided by inheritors between themselves. And if in the child’s level, there is no other inheritors, if it is born alive, is entitled to all the inheritance, otherwise will be divided between other inheritors; therefore, on its own, the foetus neither owns nor inherits.
source : shafaqna