【C++】問題解決:error: ‘rapidjson::GenericValue<Encoding, Allocator>::GenericValue(const rapidjson::GenericValue<Encoding, Allocator>&) [with Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<>]’ is private within this context

問題描述

碰到以下開頭的內容,問題的解決方式

error: ‘rapidjson::GenericValue<Encoding, Allocator>::GenericValue(const rapidjson::GenericValue<Encoding, Allocator>&) [with Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<>]’ is private within this context

問題來源

我原先想進行以下的操作

Value value6 = document["key6"]; 

出問題的段落在於我嘗試指派一個 private 成員給 Value 變數,
但因為如同上面敘述中的 「is private within this context」,導致私有成員的變數被禁止取用。
(利用 function 作為資料的參考也會碰到同樣的問題。)

解決方法

我們改取用位址,即可解決這個問題。

Value &value6 = document["key6"]; 

Reference

Licensed under CC BY-NC-SA 4.0