微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JSONCPP bug


method_cfg["input_method"][0].asstring()

错误

test1.cpp:40:46: error: ambiguous overload for ‘operator[]’ in ‘method_cfg.Json::Value::operator[](((const char*)"input_method"))[0]’
test1.cpp:40:46: note: candidates are:
/usr/include/json/value.h:277:14: note: Json::Value& Json::Value::operator[](Json::Value::UInt)
/usr/include/json/value.h:281:20: note: const Json::Value& Json::Value::operator[](Json::Value::UInt) const
/usr/include/json/value.h:294:14: note: Json::Value& Json::Value::operator[](const char*)
/usr/include/json/value.h:296:20: note: const Json::Value& Json::Value::operator[](const char*) const
/usr/include/json/value.h:298:14: note: Json::Value& Json::Value::operator[](const string&)
/usr/include/json/value.h:300:20: note: const Json::Value& Json::Value::operator[](const string&) const


原因和解答:

原因很简单,当是常量值0的时候,无法确定把它当作是 UINT 还是const char*,string来处理。

使用method_cfg["input_method"][0U].asstring()或者使用变量 int n=0来代替

原文地址:https://www.jb51.cc/json/289574.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐