I know this should be a question n00b, but I have to implement an application for sequential interaction with the mockup client server, and since the number of client-server calls is changing, I canβt just repeat the steps in the external function, always getting the data from the client, and then forward it to the server and vice versa, so I need my Server and Client classes to know about each other so that they can call their public methods among themselves. One approach would be to develop as singleton, but I was hoping to do it in a simpler way, more precisely using a circular link: the client stores a link to the server, and the server stores a link to the client. I know this may not be a very good approach, and this can cause the call stack to explode when it gets too deep , so any improvements in my design are welcome.
To achieve the described implementation, I thought that I could use std::shared_ptr because std::unique_ptr will not work if I also want the two variables from main not to be knocked down when I call two setters (right? ) So this is what I have (simplified code):
#include <iostream>
Unfortunately, my code seems to be trying to repeatedly call client and server destructors (implicit), or some similar unpleasant things, and I'm sure this is due to my poor understanding of how std::shared_ptr Work. Please inform.
source share