← Back to Classes
Question 178
Friend Function That Builds a New Object
Friend Function That Builds a New Object
Create a class Box with a private int volume set by its constructor, plus a public intgetVolume()const. Write a friend function BoxmergeBoxes(const Box& a, const Box& b)that returns a NEW Box whose volume is the sum of the two boxes' volumes. The friend function needs direct access to the private volume of both boxes. Do NOT write a main function.
Expected Output:
30 12
= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
ClassesFriend Functions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.