CJCoding With Joseph
15per day

Friend Function That Builds a New Object

Create a class Box with a private int volume set by its constructor, plus a public int getVolume() const. Write a friend function Box mergeBoxes(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
Topics:
ClassesFriend Functions
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.