Fsmbase.h

#include<iostream>
#include<string>
#include<vector>

class FSMBase {
public:
      std::string StateName;
      std::string EventName;
      std::vector<FSMBase*> subitem;


      FSMBase();
      void getdata();
      virtual void Add(FSMBase* b1);
      ~FSMBase();
};
Fsmbase.cpp

#include<iostream>
#include<string>
#include<vector>
#include<rapidjson/document.h>
#include<rapidjson/filereadstream.h>
#include<fstream>
#include "FSMBase.h"
#include "PrimitiveTool.h"
#include "Event.h"
#include "State.h"
#include "FSMBuilder.h"

using namespace std;
using namespace rapidjson;



      FSMBase::FSMBase()
      {
            std::cout << "default constructor called" << std::endl;
      }

      void FSMBase::getdata()
      {
            std::cout << "FSMBase called" << std::endl;
      }


      void FSMBase::Add(FSMBase* b1)
      {
            subitem.push_back(b1);
            b1->getdata();
      
      }

      FSMBase::~FSMBase()
      {
            std::cout << " destructor called" << std::endl;
      }


int main()
{

      Document doc;
      ifstream file("FSMImplementationJSON.json");
      if (!file.is_open()) {
            cerr << "Could not open file: FSMImplementationJSON.json" << endl;
            return 1;
      }

      string json((istreambuf_iterator<char>(file)),
            istreambuf_iterator<char>());

      doc.Parse(json.c_str());

      if (doc.HasParseError()) {
            cerr << "Error parsing JSON: "
                  << doc.GetParseError() << endl;
            return 1;
      }
      
      PrimitiveTool* prTool1 = new PrimitiveTool();
      FSMBuilder::createStatesFromJson(prTool1, doc);

      delete prTool1;
      return 0;
}

PrimitiveTool.h

#pragma once
#include "FSMBase.h"
class PrimitiveTool :
    public FSMBase
{
public:
    void Add(FSMBase* b1);

};


PrimitiveTool.cpp

#include "PrimitiveTool.h"

void PrimitiveTool::Add(FSMBase* b1)
{
      subitem.push_back(b1);
      b1->getdata();
}

State.h

#pragma once
#include "FSMBase.h"
#include "Event.h"

class State :
    public FSMBase
{
public:
    std::string EntreyMethodName;
    std::vector<Event*> eventitem;

    void getdata(const std::string Name, const std::string Methodname);
    void Add(FSMBase* fsmbase1);

};

State.cpp


#include "State.h"

void State::getdata(const std::string Name, const std::string Methodname)
{
      StateName = Name;
      EntreyMethodName = Methodname;
      std::cout << "  " << StateName << "  " << EntreyMethodName << std::endl;
}

void State::Add(FSMBase* fsmbase1)
{
      subitem.push_back(fsmbase1);
      fsmbase1->getdata();
}

FsmBuilder.cpp

#include "FSMBuilder.h"
#include "rapidjson/document.h"
#include <fstream>

using namespace rapidjson;
using namespace std;

void FSMBuilder::createStatesFromJson(PrimitiveTool* primitiveTool, rapidjson::Document& doc)
{
      
      if (doc.HasMember("PrimitiveTool") && doc["PrimitiveTool"].HasMember("State") && doc["PrimitiveTool"]["State"].IsArray()) {
            const Value& states = doc["PrimitiveTool"]["State"];
            for (SizeType i = 0; i < states.Size(); ++i) {
                  const Value& stateVal = states[i];
                  State* StateObj = new State();

                  if (stateVal.HasMember("Name") && stateVal["Name"].IsString()) {
                        StateObj->getdata(stateVal["Name"].GetString(), stateVal["EntryMethodName"].GetString());
                  }

                  if (stateVal.HasMember("Event")) {
                        if (stateVal["Event"].IsArray()) {
                              const Value& events = stateVal["Event"];
                              for (SizeType j = 0; j < events.Size(); ++j) {
                                    const Value& eventVal = events[j];
                                    Event* EventObj = new Event();

                                    if (eventVal.HasMember("Name") && eventVal["Name"].IsString()) {
                                          string eventName = eventVal["Name"].GetString();
                                          string actionType = eventVal.HasMember("ActionType") ? eventVal["ActionType"].GetString() : "";
                                          string actionParam = eventVal.HasMember("ActionParam") ? eventVal["ActionParam"].GetString() : "";
                                          EventObj->getdata(eventName, actionType, actionParam);
                                          StateObj->Add(EventObj);
                                    }
                              }
                        }
                  }
                  primitiveTool->Add(StateObj);
            }
      }
}

And i want to write a function called InEvent() in PrimitiveTool class such that when the "change state" action takes place the corresponding event object should get passed to the currently active state