
Joel de Guzman wrote:
While trying to generate a small example, I found out, what is causing the problem: I marked the grammar class using the closure with __declspec(dllexport), which causes MSVC to instantiate all members of a template, even if they are never needed. It seems that otherwise the "context" member function is never instantiated. If you remove the __declspec(dllexport), everything compiles. I still think, that the code is wrong, because it returns a pointer, where it should return a reference. I have attached a small example, which triggers the problem.
No it is not. You can return a reference to a pointer. Example:
char const*& foo() { static char const* s = "hi"; return s; }
By the way, the example implements a real parser, which uses the standard C++ runtime to convert the real number into a double. I had to implement this, because I found out, that the Spirit real_p parser creates numerically different results from the standard runtime, i.e. parsing the string "1.8" delivers a number like 1.8000000532 using Spirit, while the C++ runtime delivers something like 1.7999999973, which is always closer to the real value. Please note, that these numbers are not accurate, they are simply meant to demonstrate, what I mean.
Wow, that's a strong accusation ;-) Again, code please. I can't seem to reproduce your result:
parse("1.8", real_p[assign_a(d)]); std::cout.setf(std::ios::fixed|std::ios::left); std::cout.precision(15); std::cout << d << std::endl;
gives me:
1.800000000000000
Hmmm... how about:
parse("1.800000000000001", real_p[assign_a(d)];
gives me:
1.800000000000001 Sorry, it wasn't meant as an accusation. I had found this out some months ago, so I tried to give an example from my memory. I didn't expect Spirit to behave exactly as iostream, because there was no specification with respect to numerical accuracy. Additionally I only found this out, when setting the precision to 20, 15 is not enough. I
I know, that you can return a reference to a pointer. But in
boost/spirit/phoenix/closures.hpp closure<..>::context() is declared to
return a reference to a closure_frame_t, which is a closure_frame