编译错误提升属性树C++
我正在尝试使用boost属性树编译自定义linux。我在文件json_parser_read.hpp(行105)上有错误编译错误提升属性树C++
struct a_literal_val {
context &c;
a_literal_val(context &c): c(c) { }
void operator()(It b, It e) const
{
BOOST_ASSERT(c.stack.size() >= 1);
c.stack.back()->push_back(std::make_pair(c.name, Str(b, e)));
c.name.clear();
c.string.clear();
}
};
这段代码无法编译。 输出为:/path/to/boost/property_tree/detail/json_parser_read.hpp:105: error: no matching function for call to 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::push_back(std::pair<std::basic_string<char>, std::basic_string<char> >)' c.stack.back()->push_back(std::make_pair(c.name, Str(b, e))); ^
我使用升压v1.49
我与其他电脑进行测试,并将其与版本编译正确1.58
感谢您的帮助。
回答:
这是您应该创建的SSCCE。我看不到你的problem¹,²:
Live On Coliru
#include <boost/property_tree/ptree.hpp> #include <deque>
using boost::property_tree::ptree;
struct context {
std::string name, string;
std::deque<ptree *> stack;
};
struct a_literal_val {
using Str = std::string;
context &c;
a_literal_val(context &c) : c(c) {}
template <typename It>
void operator()(It b, It e) const {
BOOST_ASSERT(c.stack.size() >= 1);
c.stack.back()->push_back(std::make_pair(c.name, ptree{Str(b, e)}));
c.name.clear();
c.string.clear();
}
};
#include <boost/property_tree/json_parser.hpp>
#include <iostream>
int main() {
boost::property_tree::ptree pt;
context ctx { "field1", "", { &pt } };
a_literal_val visitor {ctx};
std::string const value = "hello world";
visitor(value.rbegin(), value.rend()); // reverse, for fun
write_json(std::cout, pt);
}
打印
{ "field1": "dlrow olleh"
}
¹除了你可能滥用加速性能作为XML或JSON库。 Boost 没有 XML或JSON库。
²是我知道你的样品比较复杂。很可能你正在为你的接口代码编写一个“通用”序列化程序。在我的水晶球中,我猜测你正在使用Boost Fusion改编的结构来处理嵌套的对象图。这一切都是以前完成的。问题是,你需要提出你有的问题,否则谁都不会知道。
以上是 编译错误提升属性树C++ 的全部内容, 来源链接: utcz.com/qa/264065.html