---- Original Message ---- From: Fritz Birnbacher
Hello,
I am new in using boost and I played a little bit with the spirit library.
I tried following code using MSVC 7.1 and boost 1.30.2
#include"stdafx.h" #include
using namespace boost::spirit;
rule<> GetRule()
rule<> r = anychar_p; return r;
void Parse1()
char s[] = "ABCD"; parse(s, GetRule());
void Parse2()
rule<> r = anychar_p; char s[] = "ABCD"; parse(s,r);
int _tmain()
Parse1(); return 0;
Parse1() throws an exception (access violation)
Parse2() works correct.
Is it a compiler problem or a problem in spirit or my problem ?
Neither. You should not return rules from functions. Rules cannot be passed by value. The copy and assignment operators do not follow the standard C++ object behavior. Instead, you wrap rules inside grammars and pass the grammar around. For that matter, v1.7 has the notion of stored_rule(s) which, unlike the rule, has C++ ctor/assign semantics, hence, can be passed around, stored inside containers, etc. HTH. BTW, Spirit has its own mailing list: Spirit-general mailing list Spirit-general@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spirit-general I took the liberty of cross-posting this there. See you there. -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net