There's fundamentally one cause of enamel decay: acidity. Typically these acids are produced by bacteria in a person's mouth as a waste product. Over time these acids wear down the tooth and create cavities. But enamel can also be worn away by acidic foods and drinks like wine, coffee, and soda.
Different diets can change the flora of bacteria in a person's mouth, just as it changes the flora in a person's gut. The bacteria that produce a lot of acids generally consume simple carbohydrates, so diets rich in simple carbohydrates are correlated with the presence of cavities. Brushing and flossing prevents the simple carbohydrates from staying in the mouth for too long, which slows bacterial growth. A diet low in simple carbohydrates also inhibits bacterial growth. (It might be more accurate to say that the bacteria don't produce acids when consuming things other than simple carbohydrates --- I'm not sure.)
Mouth flora tends to be similar between members of a family. Parents pass their own flora on to their children, and over time the flora of spouses tends to become similar as well.
It's possible that your diet was conducive to good tooth health, or it's possible that you lucked out with your mouth flora, or both.
(I got a cavity a few years ago and ended up reading a bunch about tooth health. But I'm not a dentist, so there may be some inaccuracies or oversimplifications in my comment.)
Edit: I forgot to mention that some people naturally have more acidic saliva than others, which is also correlated with cavities. As far as I know, that's purely genetic.