I was following the tutorials in the Spirit documentation, and I'm stuck here:
#include <iostream> #include <string> #include <boost/spirit/include/qi.hpp> template <typename Iterator> bool parse_numbers(Iterator first, Iterator last, double &sum) { namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; namespace ph = boost::phoenix; bool r = qi::phrase_parse( first, last, // begin grammar ( qi::double_[ph::ref(sum) = qi::_1] >> *(',' >> qi::double_[ph::ref(sum) += qi::_1]) ) // end grammar , ascii::space ); if (first != last) return false; return true; } int main(int argc, char **argv) { std::string str = argv[1]; double sum; bool result = parse_numbers(str.begin(), str.end(), sum); if (result) { std::cout << "Sum: " << sum << std::endl; return 0; } std::cout << "Invalid Input" << std::endl; return 1; } When I compile it, it shows this error:
$ c++ spirit-test.c++ spirit-test.c++: In function ‘bool parse_numbers(Iterator, Iterator, double&) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]’: spirit-test.c++:32:57: instantiated from here spirit-test.c++:21:2: error: no match for ‘operator+=’ in ‘boost::phoenix::ref [with T = double](((double&)((double*)sum))) += boost::spirit::_1’ spirit-test.c++:21:2: error: no match for ‘operator=’ in ‘boost::phoenix::ref [with T = double](((double&)((double*)sum))) = boost::spirit::_1’ /usr/include/boost/spirit/home/phoenix/core/actor.hpp:143:16: note: candidate is: boost::phoenix::actor<Eval>& boost::phoenix::actor<Eval>::operator=(const boost::phoenix::actor<Eval>&) [with Eval = boost::phoenix::reference<double>, boost::phoenix::actor<Eval> = boost::phoenix::actor<boost::phoenix::reference<double> >] What's wrong?
" . . . "(4 leading spaces) instead of<code>.M-x increase-indent. With<code>, all phrases inside<and>disappear, so your code looked a lot more wrong (without any template parameters) than it actually was :)