简体   繁体   中英

Error passing rapidjson::Value type to another function

I needed to pass a variable with rapidjson::Value type to another function with the following code:

#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);

}

when I encountered the error 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

at

processJsonValue(testMember);

I never encountered such error before and have been seeking a solution for a long time on the Internet, But no use. Please help or give some ideas how I can solve this problem.

The error says

rapidjson::GenericValue<Encoding, Allocator>::GenericValue(const
rapidjson::GenericValue<Encoding, Allocator> &rhs) (...) is inaccessible

That looks like a copy constructor to me. If the error is thrown at processJsonValue(testMember) , try making your processJsonValue function take parameters by reference:

static void processJsonValue(Value& jsonValue) {
   // code here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM