提振精神:错误C2664,无法将'常量的boost ::凤::演员&LT;评估和演示&GT;'到“字符” [英] Boost Spirit: Error C2664, Cannot convert 'const boost::phoenix::actor<Eval>' to 'char'
本文介绍了提振精神:错误C2664,无法将'常量的boost ::凤::演员&LT;评估和演示&GT;'到“字符”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来提升精神,并努力写出使用Boost精神2.4.2(升压1.46.1)JSON解析器。对于下面的code,我在尝试执行语义动作/属性时出现错误:
错误1错误C2664:无效(字符):不能转换参数1'常量的boost ::凤::演员&LT;评估和演示&GT;'到字符
我看到了一些问题,但他们并不真正适用于我的情况。请好心帮。谢谢!
的#include&LT;地图和GT;
#包括LT&;串GT;
#包括LT&;矢量&GT;
#包括LT&;&iostream的GT;#包括LT&;升压/配置/ warning_disable.hpp&GT;
#包括LT&;升压/精神/有/ qi.hpp&GT;
#包括LT&;升压/精神/有/ phoenix_core.hpp&GT;
#包括LT&;升压/精神/有/ phoenix_operator.hpp&GT;
#包括LT&;升压/精神/有/ phoenix_stl.hpp&GT;
#包括LT&;升压/精神/有/ phoenix_object.hpp&GT;
#包括LT&;升压/精神/有/ phoenix_container.hpp&GT;
#包括LT&;升压/精神/有/ phoenix_function.hpp&GT;
#包括LT&;升压/精神/有/ phoenix_fusion.hpp&GT;
#包括LT&;升压/融合/有/ adapt_assoc_struct.hpp&GT;
#包括LT&;升压/融合/有/ io.hpp&GT;
#包括LT&;升压/ bind.hpp&GT;
#包括LT&;升压/ function.hpp&GT;命名空间补气=的boost ::精神::补气;
命名空间ASCII =的boost ::精神:: ASCII;
命名空间凤=提振::凤;无效PRINT_CHAR(焦三)
{
性病::法院LT&;&LT; C;
}模板&LT; typename的迭代器&GT;
结构json_grammar:补气::语法&LT;迭代器,ASCII ::空间类型&GT;
{
json_grammar():json_grammar :: base_type(开始)
{
使用ASCII字母::;
使用ASCII :: alnum;
使用气:: long_long;
使用气:: long_double;
用气点燃::;
使用气:: char_;
使用气::词位;
TYPEDEF的boost ::功能和LT;无效(炭)GT; char_action_t; // char_action_t beginObj(的boost ::绑定(安培; PRINT_CHAR,补气:: _ 1)); //
开始=
烧焦_({)的boost ::绑定(安培; PRINT_CHAR,补气:: _ 1)]
&GT;&GT; - (js_member%',')
&GT;&GT; char_(})
;
//
js_member =
js_key
&GT;&GT; ':'&GT;&GT; js_value
;
//
js_key =(阿尔法&GT;&GT; * alnum)| js_string
;
//
js_string = js_single_quoted_str | js_double_quoted_str
;
//
js_array =亮起('[')GT;&GT; - (js_value%',')GT;&GT;点亮(']')
;
//
js_bool =点亮(真)|点亮(假)
;
//
js_null =点亮(空)
;
//
js_value = js_string | js_num | js_array |开始| js_bool | js_null | js_empty_str;
//
js_single_quoted_str =(语义['&GT;&GT; +((char_ |''|\\ t的) - ')&GT;&gt;中]);
//
js_double_quoted_str =(语义[''&GT;&GT; +((char_ |''|\\ t的) - ')GT;&GT;'']);
//
js_empty_str =亮('')|点亮(\\\\);
//
js_num = long_long | long_double;
} 齐::规则&LT;迭代器,ASCII ::空间类型&GT;开始;
齐::规则&LT;迭代器,ASCII ::空间类型&GT; js_member;
齐::规则&LT;迭代器,ASCII ::空间类型&GT; js_key;
齐::规则&LT;迭代器,ASCII ::空间类型&GT; js_value;
齐::规则&LT;迭代器,ASCII ::空间类型&GT; js_string;
齐::规则&LT;迭代器,ASCII ::空间类型&GT; js_single_quoted_str;
齐::规则&LT;迭代器,ASCII ::空间类型&GT; js_double_quoted_str;
齐::规则&LT;迭代器,ASCII ::空间类型&GT; js_empty_str;
齐::规则&LT;迭代器,ASCII ::空间类型&GT; js_array;
齐::规则&LT;迭代器,ASCII ::空间类型&GT; js_num;
齐::规则&LT;迭代器,ASCII ::空间类型&GT; js_null;
齐::规则&LT;迭代器,ASCII ::空间类型&GT; js_bool;
};诠释的main()
{
标准::字符串inputStr;
json_grammar&LT;的std ::字符串::为const_iterator&GT; jsonParser;
布尔parseOK = FALSE; 而(的std ::函数getline(给std :: cin,inputStr)){
如果(inputStr.empty()|| inputStr [0] =='Q'|| inputStr [0] =='Q')
打破; 标准::字符串::为const_iterator ITER = inputStr.begin();
标准::字符串::为const_iterator iterEnd = inputStr.end(); parseOK =齐:: phrase_parse(ITER,iterEnd,jsonParser,ASCII ::空间); 如果(parseOK&安培;&安培; ITER == iterEnd){
性病::法院LT&;&LT; 成功解析了输入作为JSON! &LT;&LT;的std :: ENDL;
}其他{
性病::法院LT&;&LT; 不能解析输入作为JSON! &LT;&LT;的std :: ENDL;
}
} 返回0;
}
解决方案
更多更新:
克斯特亚具有良好的点半壁江山倒是基地:的boost ::绑定
其实很好,只是使用不同的占位符:
[的boost ::绑定(安培; PRINT_CHAR,:: _ 1)]
[凤凰::绑定(安培; PRINT_CHAR,补气:: _ 1)]
[PRINT_CHAR]
这三个应该工作,但不能混合:)
I'm new to Boost Spirit and trying to write JSON parser using Boost Spirit 2.4.2 (Boost 1.46.1). For the code below, I get the error when trying to execute semantic action/attribute:
Error 1 error C2664: 'void (char)' : cannot convert parameter 1 from 'const boost::phoenix::actor<Eval>' to 'char'
I saw some questions but they don't really apply to my case. Please kindly help. Thank you!
#include <map>
#include <string>
#include <vector>
#include <iostream>
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/spirit/include/phoenix_container.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/fusion/include/adapt_assoc_struct.hpp>
#include <boost/fusion/include/io.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
namespace phoenix = boost::phoenix;
void print_char(char c)
{
std::cout << c;
}
template <typename Iterator>
struct json_grammar : qi::grammar<Iterator, ascii::space_type>
{
json_grammar() : json_grammar::base_type(start)
{
using ascii::alpha;
using ascii::alnum;
using qi::long_long;
using qi::long_double;
using qi::lit;
using qi::char_;
using qi::lexeme;
typedef boost::function<void(char)> char_action_t;
//char_action_t beginObj (boost::bind(&print_char, qi::_1));
//
start =
char_('{') [boost::bind(&print_char, qi::_1)]
>> -(js_member % ',')
>> char_('}')
;
//
js_member =
js_key
>> ':' >> js_value
;
//
js_key = (alpha >> *alnum) | js_string
;
//
js_string = js_single_quoted_str | js_double_quoted_str
;
//
js_array = lit('[') >> -(js_value % ',') >> lit(']')
;
//
js_bool = lit("true") | lit("false")
;
//
js_null = lit("null")
;
//
js_value = js_string | js_num | js_array | start | js_bool | js_null | js_empty_str;
//
js_single_quoted_str = (lexeme["'" >> +((char_ | ' ' | "\t") - "'") >> "'"]);
//
js_double_quoted_str = (lexeme['"' >> +((char_ | ' ' | "\t") - '"') >> '"']);
//
js_empty_str = lit("''") | lit("\"\"");
//
js_num = long_long | long_double;
}
qi::rule<Iterator, ascii::space_type> start;
qi::rule<Iterator, ascii::space_type> js_member;
qi::rule<Iterator, ascii::space_type> js_key;
qi::rule<Iterator, ascii::space_type> js_value;
qi::rule<Iterator, ascii::space_type> js_string;
qi::rule<Iterator, ascii::space_type> js_single_quoted_str;
qi::rule<Iterator, ascii::space_type> js_double_quoted_str;
qi::rule<Iterator, ascii::space_type> js_empty_str;
qi::rule<Iterator, ascii::space_type> js_array;
qi::rule<Iterator, ascii::space_type> js_num;
qi::rule<Iterator, ascii::space_type> js_null;
qi::rule<Iterator, ascii::space_type> js_bool;
};
int main()
{
std::string inputStr;
json_grammar<std::string::const_iterator> jsonParser;
bool parseOK = false;
while(std::getline(std::cin, inputStr)) {
if(inputStr.empty() || inputStr[0] == 'q' || inputStr[0] == 'Q')
break;
std::string::const_iterator iter = inputStr.begin();
std::string::const_iterator iterEnd = inputStr.end();
parseOK = qi::phrase_parse(iter, iterEnd, jsonParser, ascii::space);
if(parseOK && iter == iterEnd) {
std::cout << "Successfully parsed the input as JSON!" << std::endl;
} else {
std::cout << "Cannot parse the input as JSON!" << std::endl;
}
}
return 0;
}
解决方案
More update:
Kostya has a good point and 'half' touches base: boost::bind
actually is fine, just use different placeholders :
[ boost::bind(&print_char, ::_1) ]
[ phoenix::bind(&print_char, qi::_1) ]
[ print_char ]
All three should work, but not mixed :)
这篇关于提振精神:错误C2664,无法将'常量的boost ::凤::演员&LT;评估和演示&GT;'到“字符”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文