I am relatively new to C++, and I have looked a lot for an answer for this thing but I never got a satisfying answer.
Let's say I have a structure called FSM. Eventually in my code, multiple instances of FSM can be created. One of FSM's attributes is int X which is not static, every instance of FSM should have its own value for X.
Now, one of FSM's attributes is another structure submachine which needs to read the value of X like this:
struct FSM
{
  public:
    int x;
    int getX(){return x;}
    struct submachine
    {
        void onentry() {int g = getX();};
    };
};
This gives the following error:
Error: 'FSM::getX' : illegal call of non-static member function
My question is, submachine is a member of FSM, so shouldn't it have access to local instances of all the attributes of FSM?  And if not, when we create an instance of FSM, wouldn't we be creating an instance of all its members i.e. submachine?  And if so, then why do we need to create an object that onentry() needs?
I am assuming the compiler is correct, so I would also want to know if there's a way to make this work.
NOTE: Unfortunately, the instances of the inner structures (submachine) are instantiated when an event is called and thus I can only define the type, and not instantiate objects for them in FSM.
 
     
     
     
     
    