A fig tree produces two kinds of figs-- edible figs and caprifigs.
Caprifigs have male and female flowers growing inside the syconium-- the outside wall of the fig. The edible kind have only male flowers.
Edible figs are sweet and juicy. Caprifigs are dry and tough and resinous.
A female fig wasp leaves the capri fig of its birthplace, and chews through the exterior of another to lay eggs in the sweet center. There her babies will grow, nourished by the female flowers of the fig. As a result, caprifigs have very few female flowers at maturity, and are no longer able to help the fig tree reseed itself(though they do wonders for reproducing fig wasps).
Conversely, when a female fig wasp burrows into an edible fig, she finds no female flowers to serve as food for her eggs. As she searches for flowers, she carried pollen from the caprifruit to each of the tinymale flowers in the edible fig, pollinating them all. Then she dies, as the fig develops around her, safe from the hungry jaws of her offspring.
Want to read more?
Try Ray's Figs.
I also found a really cool picture of a fig wasp preserved in amber on Nova's site.