A well-established Halacha forbids partaking of milk or dairy products within six hours after one has eaten meat (Shulhan Aruch, Yoreh De'a 89:1). The authorities address a situation where a person forgot that he had eaten meat within the previous six hours and prepares to eat a dairy food, such a cheese. Immediately after reciting the Beracha over the cheese, but before taking the first bite, he remembers that it is forbidden for him to eat cheese because he had recently partaken of meat. What should a person do in such a situation?
Instinctively, one might argue that a person in this case should eat a piece of the cheese so that the Beracha he recited would not constitute a "Beracha Le'vatala" – a "wasted" Beracha. Even though he will have transgressed the Rabbinic enactment forbidding the consumption of cheese within six hours of eating meat, it is perhaps preferable to violate this prohibition to avoid violating the more grievous prohibition of "Beracha Le'vatala." In truth, however, partaking of the cheese might not achieve the desired goal of legitimizing the Beracha. When a person eats food that Halacha forbids for consumption, he does not recite a Beracha before eating, and if he does recite a Beracha, it is considered a "Beracha Le'vatala." According to the Rambam (Rabbi Moshe Maimonides, Spain-Egypt, 1135-1204), this Halacha applies even when eating foods that are permissible by Torah but forbidden by force of Rabbinic enactment. In our case, then, if one eats the cheese his Beracha will nevertheless be deemed a "Beracha Le'vatala," as it was recited over forbidden food.
Hacham Ovadia Yosef discusses this question in his work Yehaveh Da'at (vol. 4, 41), and rules that a person this case should, in fact, eat a piece of the cheese. He arrives at this ruling based on a "Sefek Sefeka," or "double doubt"; meaning, two questionable Halachot are at stake in this situation. Firstly, the Tosafists (Medieval school of French and Germany Talmud scholars) held that one who eats meat may partake of dairy foods once he has recited "Birkat Ha'mazon" and thus concluded the meat meal. In their view, one is not required to wait six hours after eating meat before eating dairy foods, and so long as the meat meal was formally concluded through the recitation of "Birkat Ha'mazon," he may eat dairy foods. Secondly, the Ra'avad (Rabbi Avraham Ben David of Posquieres, 1120-1350) was of the opinion that one does, in fact, recite a Beracha over forbidden food that he eats. Thus, although the Shulhan Aruch does not follow these two views, they result in a "Sefek Sefeka" in that two questionable assumptions must be made for us to consider the Beracha recited over the cheese a "Beracha Le'vatala." Hence, Hacham Ovadia rules that in this case one should eat a piece of cheese in order that his Beracha should not be considered a "wasted" Beracha.
Although Rabbi Moshe Halevi (Israel, 1961-2001) disputes this ruling (Birkat Hashem, vol. 2, p. 82), a person who finds himself in this situation should follow the ruling of Hacham Ovadia Yosef and eat a piece of the cheese.
Summary: If a person planned to eat cheese (or any other dairy product) within six hours of having eaten meat, and immediately after reciting the Beracha he recalled that he had recently eaten meat, he should take a bite of the cheese so that the Beracha will not be considered a "Beracha Le"vatala."