Problem compiling a statemachine with "class" instead of "struct"
Hi folks,
we have run into an interesting problem when compiling
one of our state machines using the boost state chart templates.
If we instantiate a state like this:
struct Active : public boost::statechart::simple_state< Active,
PRX5StateMachine >
{
public:
Active() : m_data("") {}
~Active() {}
std::string & Data() { return m_data;}
const std::string& Data() const { return m_data; }
private:
std::string m_data;
};
and use it in our code, everything compiles fine. As soon as we
change the declaration to
class Active : public boost::statechart::simple_state< Active,
PRX5StateMachine >
we get massive compiler errors, which look like this:
/usr/include/boost/statechart/simple_state.hpp:832: error: within this
context
/usr/include/boost/statechart/state_machine.hpp:243: error: ‘typedef
struct boost::statechart::detail::rtti_policy
boost::statechart::state_machine
and use it in our code, everything compiles fine. As soon as we change the declaration to
class Active : public boost::statechart::simple_state< Active, PRX5StateMachine >
we get massive compiler errors, which look like this:
In "struct" its memebers have "public" access by default. In you define a "class", ensure that all the symbols needed by the framework are accessible (eg., that "reactions" typedef is public)
In "struct" its memebers have "public" access by default. In you define a "class", ensure that all the symbols needed by the framework are accessible (eg., that "reactions" typedef is public)
I just mailed the sample code to this list. As far as I could see whe carefully included the public and private keywords in all relevant locations.
I just mailed the sample code to this list. As far as I could see whe carefully included the public and private keywords in all relevant locations.
You probably forgot to attach the files or your mail-server filtered them out.
What happens if you change:
class PRX5StateMachine : boost::statechart::state_machine< PRX5StateMachine,
Active > {};
To:
class PRX5StateMachine : public boost::statechart::state_machine<
PRX5StateMachine, Active > {};
2009/2/17 Rudolf Leitgeb
You probably forgot to attach the files or your mail-server filtered them
out.
Shame on me :(
Here they are.
Cheers,
Rudi
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks, that solved the problem! We did put the public inheritance into the Active declaration but forgot the other state machine :( Cheers, Rudi Am 17.02.2009 um 15:45 schrieb Igor R:
What happens if you change: class PRX5StateMachine : boost::statechart::state_machine< PRX5StateMachine, Active > {}; To: class PRX5StateMachine : public boost::statechart::state_machine< PRX5StateMachine, Active > {};
Hi Rudolf [snip]
If we instantiate a state like this:
struct Active : public boost::statechart::simple_state< Active, PRX5StateMachine > { public: Active() : m_data("") {} ~Active() {}
std::string & Data() { return m_data;}
const std::string& Data() const { return m_data; }
private: std::string m_data; };
and use it in our code, everything compiles fine. As soon as we change the declaration to
class Active : public boost::statechart::simple_state< Active, PRX5StateMachine >
we get massive compiler errors, which look like this: [snip error message]
Is it mandatory to inherit from simple_state via a struct and not from a class?
As Igor has already pointed out (thanks, Igor!), you *should* be able to use class instead of struct, as long as you ensure that everything needed by Boost.Statechart is public. However, I'm a bit puzzled by your example code above, as it does not contain any reactions typedef. Is that intentional? If so, then just changing class to struct should not cause the errors you report. If the amount of code is small (< 10k) you can post it here otherwise please send me the code by private email, see below for instructions. By the way, please always add [statechart] to your subject line when asking questions regarding Boost.Statechart. This will usually ensure a much speedier response from me and also help other group members to filter the messages they are interested in. Regards, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
As Igor has already pointed out (thanks, Igor!), you *should* be able to use class instead of struct, as long as you ensure that everything needed by Boost.Statechart is public. However, I'm a bit puzzled by your example code above, as it does not contain any reactions typedef. Is that intentional?
The code snippet supplied was a heavily reduced sample piece. We tried to keep our sample code as simple as possible to avoid confusion. The state machine does nothing useful except highlight the problem we encountered with a much more complex state machine.
If so, then just changing class to struct should not cause the errors you report. If the amount of code is small (< 10k) you can post it here otherwise please send me the code by private email, see below for instructions.
The sample code is very small so I send it attached with this email. There are two zip files, the one called class_test.zip contains the code which triggers the problem. structversion.zip is essentially the same code, except that state Active is now declared as struct. This version compiles without a problem.
By the way, please always add [statechart] to your subject line when asking questions regarding Boost.Statechart. This will usually ensure a much speedier response from me and also help other group members to filter the messages they are interested in.
Sorry, this was my first post to this forum. I've noticed it from other posts to this list in the mean time. Cheers, Rudi
participants (3)
-
Andreas Huber
-
Igor R
-
Rudolf Leitgeb