Two objects need to reference each other as part of their design.
However, when both objects own each other using std::shared_ptr, a cyclic ownership is created.
In such a design:
The given program already demonstrates this problem.
Your task is to modify the ownership design so that:
What You Must Do:
Program Flow:
Current Behavior (Buggy):
Correct Behavior (After Fix):
"End of scope" is printedExample Output (After Fix):
A destroyed
B destroyed
End of scope
Constraints:
Input
Expected Output
A destroyed B destroyed End of scope