title: How to exit a submachine in a hierarchial-SM that is split into multiple files? (using boost::MSM)
body: <p>There is a good tutorial that explains how we can use the "exit-pseudo-state" to exit from a submachine using <code>boost::MSM</code>, <a href="http://redboltz.wikidot.com/exit-point-pseudo-state" rel="nofollow noreferrer">here</a>.</p>
  
  <p>But I need to split my SM into multiple files, to keep it manageable, and here is where the problem arises.</p>
  
  <p>When the sub-SM is defined in the main fsm file, everything works fine, i.e. exiting from the "exit-pseudo-state" results in a an exit from the sub-SM into the next state(<a href="https://wandbox.org/permlink/1KFCiGKV7du6ieBw" rel="nofollow noreferrer">sample code</a>)</p>
  
  <p>Implementing the sub-SM in a separate file, where I have to make an extra level of dummy inheritance, causes problems. 
  This time the transition to the exit-pseudo-state in the internal sub-SM does not trigger an exit to the the next state in the parent-SM. <a href="https://wandbox.org/permlink/kDJ4xiUI9MuqA5TL" rel="nofollow noreferrer">Here</a> is a sample code showing the problem.</p>
  
  <p>As you can see from the output below, <code>State2::on_exit()</code> is missing at the end after exiting substate21</p>
  
  <pre><code>Testing boost::msm ...
  State1::on_entry()
  State1::on_exit()
  State2::on_entry()
  SubState21::on_entry()
  SubState21::on_exit()
  </code></pre>
  
  <p>Thanks for your help in advance</p>
  
  <p>Code included:</p>
  
  <p>main file:</p>
  
  <pre><code>#include "myfsm.h"
  
  int main()
  {    
      std::cout &lt;&lt; "Testing boost::msm ..." &lt;&lt; std::endl;
      MyFsm fsm;
      fsm.start();
  
      fsm.process_event(Event1());
      fsm.process_event(Event3());
      //fsm.process_event(Event2());
  }
  </code></pre>
  
  <p>main fsm:</p>
  
  <pre><code>#include &lt;boost/msm/back/state_machine.hpp&gt;
  #include &lt;boost/msm/front/state_machine_def.hpp&gt;
  #include &lt;boost/msm/front/functor_row.hpp&gt;
  
  #include "state2.h"
  #include "events.h"
  
  namespace msm = boost::msm;
  namespace msmf = boost::msm::front;
  namespace mpl = boost::mpl;
  
  struct MyFsm_ : msmf::state_machine_def&lt;MyFsm_&gt;
  {
      struct State1 : msmf::state&lt;&gt;{
          template&lt;class Event, class Fsm&gt; void on_entry(const Event&amp;, Fsm&amp;) const {std::cout &lt;&lt; "State1::on_entry()" &lt;&lt; std::endl;}
          template&lt;class Event, class Fsm&gt; void on_exit(const Event&amp;, Fsm&amp;) const {std::cout &lt;&lt; "State1::on_exit()" &lt;&lt; std::endl;}
      };    
  
      struct State2m : State2 {};
  
     // Set initial state
     typedef State1 initial_state;
  
     // Transition table
     struct transition_table:mpl::vector&lt;
           msmf::Row &lt; State1, Event1, State2m, msmf::none, msmf::none &gt;,
           msmf::Row &lt; State2m, Event2, State1, msmf::none, msmf::none &gt;,
           msmf::Row &lt; State2::exit_pt
                       &lt;State2_::Exit2&gt;, msmf::none, State1, msmf::none, msmf::none &gt;
     &gt;{};
  
    template&lt;class Event, class Fsm&gt;
     void no_transition(Event const&amp;, Fsm&amp;, int state){
         std::cout&lt;&lt;"no_transiton detected from state: "&lt;&lt; state &lt;&lt; std::endl;
     }
  
  };
  // Pick a back-end
  typedef msm::back::state_machine&lt;MyFsm_&gt; MyFsm;    
  </code></pre>
  
  <p>sub-SM i.e. state2.h:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/msm/back/state_machine.hpp&gt;
  #include &lt;boost/msm/front/state_machine_def.hpp&gt;
  #include &lt;boost/msm/front/functor_row.hpp&gt;
  #include "events.h"
  
  namespace msm = boost::msm;
  namespace msmf = boost::msm::front;
  namespace mpl = boost::mpl;
  
  
  struct State2_ : msmf::state_machine_def&lt;State2_&gt;{
          template&lt;class Event, class Fsm&gt; void on_entry(const Event&amp;, Fsm&amp;) const {std::cout &lt;&lt; "State2::on_entry()" &lt;&lt; std::endl;}
          template&lt;class Event, class Fsm&gt; void on_exit(const Event&amp;, Fsm&amp;) const {std::cout &lt;&lt; "State2::on_exit()" &lt;&lt; std::endl;}
  
          struct SubState21 : msmf::state&lt;&gt;{
              template&lt;class Event, class Fsm&gt; void on_entry(const Event&amp;, Fsm&amp;) const {std::cout &lt;&lt; "SubState21::on_entry()" &lt;&lt;std::endl;}
              template&lt;class Event, class Fsm&gt; void on_exit(const Event&amp;, Fsm&amp;) const {std::cout &lt;&lt; "SubState21::on_exit()" &lt;&lt; std::endl;}
          };
          typedef mpl::vector&lt;SubState21&gt; initial_state;
          struct Exit2 : msmf::exit_pseudo_state&lt;msmf::none&gt; {};
  
          struct transition_table:mpl::vector&lt;
              msmf::Row &lt; SubState21, Event3, Exit2, msmf::none, msmf::none &gt;
             &gt;{};
  
      };
      typedef msm::back::state_machine&lt;State2_&gt; State2;
  </code></pre>