title: function parser using boost-spirit
body: <p>I'm trying to parse functions using boost spirit. I get a compilation error when I try to save the matching function into string.</p>
  
  <blockquote>
    <p>Parser.cpp:50:58: error: call of overloaded ‘ref(std::string&amp;)’ is
    ambiguous int_[ ref(a) = _1 ] >> p.definedFunctions [ref(myFunction) =
    _1]</p>
  </blockquote>
  
  <p>The code works fine when replace 
  <code>[ref(myFunction) = _1]</code> with <code>[std::cout&lt;&lt;_1]</code></p>
  
  <h1>Parser.h</h1>
  
  <pre><code>#include &lt;spirit/include/qi.hpp&gt;
  #include &lt;iostream&gt;
  #ifndef PARSER_H
  #define PARSER_H
  
  namespace qi = boost::spirit::qi;
  class Parser {
  public:
      Parser();
      Parser(const Parser&amp; orig);
      virtual ~Parser();
      static std::string parseFuncion(const std::string&amp; s);
  
  private:
      qi::symbols&lt;char, std::string&gt; definedFunctions;
  };
  
  #endif /* PARSER_H */
  </code></pre>
  
  <h1>Parser.cpp</h1>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;stdexcept&gt;
  #include &lt;cstdlib&gt;
  #include &lt;sstream&gt;
  
  #include &lt;spirit/include/qi.hpp&gt;
  #include &lt;spirit/include/phoenix.hpp&gt;
  
  #include "Parser.h"
  namespace qi = boost::spirit::qi;
  
  Parser::Parser() {
      definedFunctions.add
              ("^"    ,      "pow")
              ("&gt;"   ,   "greater")
              ;
  }
  
  Parser::Parser(const Parser&amp; orig) {
  }
  
  Parser::~Parser() {
  }
  
  std::string Parser::parseFuncion(const std::string&amp; s){
      using boost::spirit::qi::_1;
      using boost::spirit::qi::int_;
      using boost::phoenix::ref;
      int a=0, b=0;
      std::string myFunction;
      Parser p;
  
      const char* first = s.data();
      const char* const end = first + s.size();
      const bool success = boost::spirit::qi::parse(first, end,
                                                    // Implementation of 'full-date' rule from EBNF grammar.
                                                    int_[ ref(a) = _1 ] &gt;&gt; p.definedFunctions [ref(myFunction) = _1]
              &gt;&gt; int_[ ref(b) = _1 ] 
              );
      if (!success || first != end) {
          throw std::logic_error("Parsing failed");
      }
      std::stringstream ss;
      ss&lt;&lt;myFunction&lt;&lt;"("&lt;&lt;a&lt;&lt;","&lt;&lt;b&lt;&lt;")";
      return ss.str();
  }
  </code></pre>