You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I observed that the macro FSM_INITIAL_STATE doesn't compile if invoked outside of the global namespace. The examples I looked at all use the global namespace so it isn't clear to me if much though was given to namespaces by the author.
example code that wont compile:
#include <tinyfsm.hpp>
namespace xxx::yyy {
// ----------------------------------------------------------------------------
// 1. Event Declarations
//
struct AAA : tinyfsm::Event { };
struct BBB : tinyfsm::Event { };
// ----------------------------------------------------------------------------
// 2. State Machine Base Class Declaration
//
struct SM : tinyfsm::MealyMachine<SM>
{
virtual void react(AAA const &) { };
virtual void react(BBB const &) { };
};
// ----------------------------------------------------------------------------
// 3. State Declarations
//
struct Wait : SM
{};
struct Off : SM
{};
FSM_INITIAL_STATE(SM, Off)
} // namespace xxx::yyy
Solution is to use the macro in the global namespace and fully qualify the state machine and state types:
#include <tinyfsm.hpp>
namespace xxx::yyy {
// ----------------------------------------------------------------------------
// 1. Event Declarations
//
struct AAA : tinyfsm::Event { };
struct BBB : tinyfsm::Event { };
// ----------------------------------------------------------------------------
// 2. State Machine Base Class Declaration
//
struct SM : tinyfsm::MealyMachine<SM>
{
virtual void react(AAA const &) { };
virtual void react(BBB const &) { };
};
// ----------------------------------------------------------------------------
// 3. State Declarations
//
struct Wait : SM
{
};
struct Off : SM
{
};
} // namespace xxx::yyy
FSM_INITIAL_STATE(xxx::yyy::SM, xxx::yyy::Off)
Is it possible to rework FSM_INITIAL_STATE to allow invocation within a custom namespace?
The text was updated successfully, but these errors were encountered:
chrisg89
changed the title
FSM_INITIAL_STATE Macro doesn't work if _FSM or _STATE are defined outside the global namespace
FSM_INITIAL_STATE Macro only works in global namespace
Nov 8, 2024
I observed that the macro
FSM_INITIAL_STATE
doesn't compile if invoked outside of the global namespace. The examples I looked at all use the global namespace so it isn't clear to me if much though was given to namespaces by the author.example code that wont compile:
Solution is to use the macro in the global namespace and fully qualify the state machine and state types:
Is it possible to rework FSM_INITIAL_STATE to allow invocation within a custom namespace?
The text was updated successfully, but these errors were encountered: