执行rapidjson的Document对象的副本 [英] Perform a copy of Document object of rapidjson

查看:296
本文介绍了执行rapidjson的Document对象的副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个类,我想在方法中返回我的类。我的类有一个 rapidjson :: Document 对象。

I'm making a class and I want to return my class inside a method. My class has a rapidjson::Document object.

您可以在这里看到先前的问题: LNK2019:未解析的外部符号 ; with rapidjson

You can see the previous problems here: LNK2019: "Unresolved external symbol" with rapidjson

正如我发现,rapidjson阻止你执行 Document 对象,然后包含文档对象的类的默认副本失败。我试图定义我自己的复制构造函数,但我需要执行对象的副本。 我看到了一种方法来假设使用 .Accept()方法,但是在 rapidjson :: Document 类中返回了很多错误:

As I discovered, rapidjson prevent you to perform any kind of copy of the Document object, and then the default copy of the class containing a Document object failed. I'm trying to define my own Copy Constructor but I need to perform a copy of the object. I saw a way to hypothetically copy the object with .Accept() method, but is returning me a lot of errors inside the rapidjson::Document class:


错误C2248:'无法访问在类'rapidjson :: GenericDocument'中声明的私有成员

error C2248: 'cannot access private member declared in class `rapidjson::GenericDocument'

这是我的复制构造函数:

This is my Copy Constructor:

jsonObj::jsonObj(jsonObj& other)
{
    jsonStr = other.jsonStr;
    message = other.message;

    //doc = other.doc;
    doc.Accept(other.doc);

    validMsg = other.validMsg;
}

我发现在库的代码(第52-54行)中,复制

I found in the code of the library (line 52-54) that "Copy constructor is not permitted".

这是我的类:

class jsonObj {
    string jsonStr;
    Document doc; 

public:
    jsonObj(string json);
    jsonObj(jsonObj& other);

    string getJsonStr();
};

方法:

jsonObj testOBJ()
{
    string json = "{error:null, message:None, errorMessage:MoreNone}";
    jsonObj b(json);
    return b; //It fails here if I return a nested class with a rapidjson::Document in it. Returning NULL works
}

因此,如何执行 Document 元素?

推荐答案

资源库 https://github.com/rjeczalik/rapidjson
拥有 DeepCopy补丁,可能会帮助您将一个文档复制到另一个文档。

Repository https://github.com/rjeczalik/rapidjson have the DeepCopy patch which might help you copy one document into another.

这篇关于执行rapidjson的Document对象的副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆