Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 classes (recipe in recipe.cpp and ingredients in ingredients.cpp). From

C++
void Recipe::show_recipe( std::ostream &out ) const
{
//print out receipe with ingredients
}

Ingredient Recipe::get_ingredient( int location) const
{
return Ingredient();
}


I am trying to print recipe ingredients from the ingredient class. How do I access them?

What I have tried:

Pointers - passing addresses - I am at a loss
Posted
Updated 3-Dec-18 23:56pm
v2
Comments
KarstenK 4-Dec-18 3:12am    
tip: include the ingredient header in the recipe and use CPallinis solution.

1 solution

I suppose your recipe should hold a container (e.g. a vector) of ingredients.
Then it may access their public methods. You just need to 'make aware' the Recipe class of the Ingredient one (that is by including the appropriate header file).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900