问题描述
我在做一个类,我想在方法中返回我的类。我的类有一个 rapidjson :: Document
对象。
I'm making a class and I want to return my class inside a method. My class has a rapidjson::Document
object.
您可以在这里看到先前的问题:
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:
这是我的复制构造函数:
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
元素?
推荐答案
资源库
拥有,可能会帮助您将一个文档复制到另一个文档。
Repository https://github.com/rjeczalik/rapidjsonhave the DeepCopy patch which might help you copy one document into another.
这篇关于执行rapidjson的Document对象的副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!