【发布时间】:2011-10-10 14:48:31
【问题描述】:
我正在使用属性树 xml 解析来编辑我的应用程序的一些设置 我创建了一个结构默认设置
struct default_settings
{
std::string imPath;
std::string calPath;
std::string solPath;
void load(const std::string &filename);
void save(const std::string &filename,const std::string &image_path,const std::string &cal_path,const std::string &sol_path);
};
void default_settings::save(const std::string &filename,const std::string &image_path,const std::string &cal_path,const std::string &sol_path)
{
ptree pt;
pt.put("default.image-path", image_path);
pt.put("default.cal-path", cal_path);
pt.put("default.sol-path", sol_path);
write_xml(filename, pt);
}
void default_settings::load(const std::string &filename)
{
ptree pt;
read_xml(filename, pt);
imPath = pt.get<std::string>("default.image-path");
calPath = pt.get<std::string>("default.cal-path");
solPath = pt.get<std::string>("default.sol-path");
}
然后我访问变量:imPath、calPath、.. 等 通过在我的应用程序 default_settings ds 中创建一个全局变量 并通过这个变量(ds.imPath)调用它们
奇怪的是,当加载完成一次但我得到一个异常时它可以工作
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::property_tree::xml_parser::xml_parser_error> > at memory location 0x0016bf54..
你有什么建议?
【问题讨论】:
-
你试过调试吗?您是否每次都使用相同的属性树作为目标?注入的错误信息是什么?
-
如你所见,我每次访问函数加载时都会创建一个新的 ptree
-
我尝试使用 1 个 ptree 作为全局变量并在每次进入函数时都使用 clear() 但仍然是同样的问题!
-
好吧,没有任何电话
load我不能假设这就是你的意思。不过,它开始看起来很有趣,您能否发布一个演示该问题的最小工作示例?如果这是“很多”的工作,请放心,90% 的时间它也会在我们看不到问题时告诉您问题 -
经过大量调试,似乎问题正是在加载函数的多次调用中!
标签: c++ visual-studio qt boost boost-propertytree