0

How to call a method that calls other methods?

I had a solution for this some time ago, but now I'm struggling to remember what it could be. anyways, the program is supposed to output a bunch of foods and their prices in a table. but when I try and call all the methods in one bigger method I keep getting errors. any ideas https://code.sololearn.com/c4ZQYpjQ6jQi/?ref=app

19th Sep 2017, 5:51 AM
X-1
X-1 - avatar
3 Antworten
+ 3
Make the method, "showInfo", void: void showInfo(). If you are only calling other functions or using a console output stream (cout), the method doing so should be void.
20th Sep 2017, 1:27 AM
Zeke Williams
Zeke Williams - avatar
+ 2
Does it work now that you have changed the method to void, @X-1 ?
20th Sep 2017, 2:08 PM
Zeke Williams
Zeke Williams - avatar
+ 1
I remember seeing an example program once that did something close to what you're talking about. It used a base class called menuItem which had a virtual function printCost(). Next, it defined various inherited classes like pizza, hamburger, coffee, salad, ...etc. each overloading the inherited printCost() function. This could then be used with a pointer to an array of menuItems, and by iteratively calling p[i]->printCost() each item will print its own price. I'm not sure if this is what you're looking for, but hopefully, it gives you some ideas.
20th Sep 2017, 5:03 AM
Justin Christensen
Justin Christensen - avatar