To some extent you are correct, being able to empathize with someone's experience depends on your having had an experience at least somewhat similar. On the other hand, I think people tend to overestimate how similar the experience has to be to the point that, taken to it's logical conclusion, would mean that no one can empathize with anyone at all because no one's experience of anything is 100% the same as someone else's.
Using the example of losing a child, here's what I mean:
If you've led a mostly sheltered life free from major suffering, and your deepest experience of loss was when you were 8 and your hamster died... yeah, just forget it, you won't be able to empathize with this experience. Your best bet is to express condolences (i.e. offer your sympathy, since you feel bad for them because they feel bad, even if you don't fully understand all the ways in which they feel bad) and offering to be there for them if they should need anything.
On the other hand, even if you've never lost a child but you have lost someone very close to you who was a huge part of your life and whom you didn't expect to lose but planned to have in your life for years, that might give you some idea of what that person is feeling, at least to the extent of knowing the pain and grief of losing someone who is a big part of your life, including grieving for all the futures you may have shared together but now won't. Yeah, it's not actually the same, but you can definitely understand some of their pain. If, in addition, you also had a pet that you were very attached to and had to spend a lot of time and effort caring for and then lost it, that might get you closer to understanding how empty their home feels now without their child, how empty their days are without all the things they used to do to care for that child, how their lives might feel empty of a center, of the meaning that this caring gave them. Yeah, obviously losing a pet isn't the same as losing a child, but it can still give you more of an idea.
Now, if you say something like "I know how you feel, because my brother died, and my dog died", you'll just make the person angry. But you can say "I know what it's like to lose someone so close to you, and how empty your life is without them", or even refer to some aspects of the experience you think they are having, like "I know how empty and hopeless you must feel right now". They might still get defensive if they know you haven't experienced the loss of a child, but then you'll know they are basically the kind of person who doesn't want you to empathize with them, and prefers to feel like their experiences are so unique they can't really be understood by others -- this isn't the most common way to feel (people generally prefer to be able to relate to others and want others to empathize), but it happens.
And as far as having the exact same experience, I don't think people usually give much thought to the fact that specific circumstances can dramatically change people's experiences. For instance, in this case, how one person experiences having a child isn't the same thing as how another one does, so losing will be different. Compare the experience of parenthood of an estranged father who, after the divorce, doesn't feel like having a connection with his kid even if he has the option, and mostly just sends some money or a gift for their birthday and x-mas, to the experience of parenthood of a father of a special needs child who is extremely invested in accommodating said special needs and makes daily efforts not only to care for his child but to enrich their life, to interact with them, to share their experience. Guess what, these two fathers will experience the untimely death of their child very, VERY differently.
So it's not enough to have "the same" experience (i.e. losing a child) to actually have the same experience (i.e. emotional reaction), and, ultimately, no one's experiences of anything are precisely the same. I think it's important to understand this and both to make an effort to empathize with people across some difference in circumstances and to accept empathy from others even if you know they can't really know exactly how you feel. The alternative is descending into solipsism, and alienation, and no one gains anything from that.