将 rapidjson::Value 类型传递给另一个函数时出错
Error passing rapidjson::Value type to another function
我需要使用以下代码将 rapidjson::Value 类型的变量传递给另一个函数:
#include "filereadstream.h"
#include "stringbuffer.h"
#include "rapidjson.h"
#include "document.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace rapidjson;
using namespace std;
static void processJsonValue(Value jsonValue) {
if (jsonValue.IsArray() && !jsonValue.Empty()) {
//jsonValue is valid
//json value processing procedure below...
}
}
void main()
{
char* chartFile = "C:\Users\DrBlindriver\Documents\test.json";
ifstream in(chartFile);
//attempt to open json file
if (!in.is_open()) {
cout << "Failed to access json file!\n";
return;
}
const string jsonContent((istreambuf_iterator<char>(in)), istreambuf_iterator<char>());
in.close();
Document jsonFile;
//read json and check for error
if ((jsonFile.Parse(jsonContent.c_str()).HasParseError()) || !(jsonFile.HasMember("testMember"))) {
cout << "Invalid json file!\n";
return;
}
Value testMember;
//attempt to pass testMember value to processJsonValue
testMember = jsonFile["testMember"];
processJsonValue(testMember);
}
当我遇到错误 E0330:
"rapidjson::GenericValue<Encoding, Allocator>::GenericValue(const rapidjson::GenericValue<Encoding, Allocator> &rhs) [with Encoding=rapidjson::UTF8, Allocator=rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator]" (declared at line 574 of "C:\Users\DrBlindriver\source\repos\RapidJsonTest\RapidJsonTest\json\document.h") is inaccessible
在
processJsonValue(testMember);
从来没有遇到过这样的错误,在网上找了很久的解决方法,但是没有用。请帮助或提供一些想法如何解决这个问题。
错误说
rapidjson::GenericValue<Encoding, Allocator>::GenericValue(const
rapidjson::GenericValue<Encoding, Allocator> &rhs) (...) is
inaccessible
对我来说,这看起来像一个复制构造函数。如果在 processJsonValue(testMember)
处抛出错误,请尝试让您的 processJsonValue
函数通过引用获取参数:
static void processJsonValue(Value& jsonValue) {
// code here
}
我需要使用以下代码将 rapidjson::Value 类型的变量传递给另一个函数:
#include "filereadstream.h"
#include "stringbuffer.h"
#include "rapidjson.h"
#include "document.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace rapidjson;
using namespace std;
static void processJsonValue(Value jsonValue) {
if (jsonValue.IsArray() && !jsonValue.Empty()) {
//jsonValue is valid
//json value processing procedure below...
}
}
void main()
{
char* chartFile = "C:\Users\DrBlindriver\Documents\test.json";
ifstream in(chartFile);
//attempt to open json file
if (!in.is_open()) {
cout << "Failed to access json file!\n";
return;
}
const string jsonContent((istreambuf_iterator<char>(in)), istreambuf_iterator<char>());
in.close();
Document jsonFile;
//read json and check for error
if ((jsonFile.Parse(jsonContent.c_str()).HasParseError()) || !(jsonFile.HasMember("testMember"))) {
cout << "Invalid json file!\n";
return;
}
Value testMember;
//attempt to pass testMember value to processJsonValue
testMember = jsonFile["testMember"];
processJsonValue(testMember);
}
当我遇到错误 E0330:
"rapidjson::GenericValue<Encoding, Allocator>::GenericValue(const rapidjson::GenericValue<Encoding, Allocator> &rhs) [with Encoding=rapidjson::UTF8, Allocator=rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator]" (declared at line 574 of "C:\Users\DrBlindriver\source\repos\RapidJsonTest\RapidJsonTest\json\document.h") is inaccessible
在
processJsonValue(testMember);
从来没有遇到过这样的错误,在网上找了很久的解决方法,但是没有用。请帮助或提供一些想法如何解决这个问题。
错误说
rapidjson::GenericValue<Encoding, Allocator>::GenericValue(const
rapidjson::GenericValue<Encoding, Allocator> &rhs) (...) is inaccessible
对我来说,这看起来像一个复制构造函数。如果在 processJsonValue(testMember)
处抛出错误,请尝试让您的 processJsonValue
函数通过引用获取参数:
static void processJsonValue(Value& jsonValue) {
// code here
}