In my particular case I have a "________App" class which is basically a wrapper for all the logic in the program. This is the class which calls the run(), update(), draw(), etc, functions. I'm also using a StateMachine class which is used to handle the different "states" of the program (e.g. the "main" state or the "pause" state). The update() and draw() methods are really just wrapper functions for the state machine's update() and draw(). It look a little bit like this...
class MyApp
{
private:
//...
Graphics gfx;
StateMachine<MyApp> state_machine;
//...
public:
//...
void update() {state_machine.draw();}
void draw() {state_machine.draw();}
//...
}
However, in order for my state_machine to properly update() and draw(), it needs access to some of MyApp's private members, such as gfx. What I'm really looking for here is a way that the StateMachine can modify the members of the MyApp class that owns it. Making the StateMachine a friend class is tempting, although I believe that it's a poor design decision. Can someone give me some advice or point me in a direction where I could read up on this?
Here's a look at my actual code:
//Sol::Application is the class I made which implements run() as well as other lower level operations.
class LogicGatesApp : public Sol::Application
{
public:
using WireGraph = SparseGraph<GraphNode, Wire>;
private:
StateMachine<LogicGatesApp> m_state_machine;
//This is the graphical component of the grid that the user will
//be interacting with
Grid m_grid;
//this is used to represent the wire circuitry logic of the program.
//each cell in the grid corresponds to a node in the wire graph.
//see the file description at the top for a visual.
WireGraph m_wire_graph;
public:
LogicGatesApp();
void update();
void draw();
//...
};
In this case, the StateMachine needs to be able to access and modify Grid and WireGraph. Particularly, in one of the states, it needs to highlight the block in the grid that the mouse is hovering over (hence the need to modify the Graphics object, and access to the Mouse object both found in Sol::Application)