【发布时间】:2014-05-13 12:52:35
【问题描述】:
当我使用 rapidjson 文档作为成员变量并这样做时:
class Test
{
rapidjson::Document m_jsonDocument;
public:
void f()
{
// WORKS FINE
rapidjson::Document document;
if (document.Parse<0>("{ \"hello\" : \"world\" }").HasParseError())
printf("ERROR PARSING JSON\n");
else
printf("%s\n", document["hello"].GetString());
// BUT HERE THROWS, WHY?
if (m_jsonDocument.Parse<0>("{ \"hello\" : \"world\" }").HasParseError())
printf("ERROR PARSING JSON\n");
else
printf("%s\n", m_jsonDocument["hello"].GetString());
}
};
当我调用 if (m_jsonDocument.Parse<0>("{ \"hello\" : \"world\" }").HasParseError()) 时,应用程序在 CTOR GenericValue(Type type) 中的 document.h 中的 flags_ = defaultFlags[type]; 在线崩溃。 Visual Studio 调试器显示“无法读取内存”。为_flags。问题是什么?成员变量和局部变量有什么区别?
编辑:我使用setResponseCallback defined here 将f 设置为回调,而f 正在使用dispatchResponseCallbacks defined here 作为回调调用。
【问题讨论】:
-
函数
f怎么调用? -
@JoachimPileborg 调用服务器获取 JSON 数据,并且在响应到达时调用回调。
f是回调函数。有关系吗? -
@JoachimPileborg 哦,这真的很奇怪。我无法理解。我已按如下方式调用
f:Test t; t.f();,它起作用了。有什么不同?我该如何解决我的问题?