我嘗試通過rapidjson :: Document對象作爲函數的參數:rapidjson對象作爲函數的參數原因編譯器錯誤
std::string json_to_string(rapidjson::Document jmsg)
{
// Convert JSON document to string
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
jmsg.Accept(writer);
std::string str = buffer.GetString();
return str;
}
如果我做了功能上面只是,我當我編譯的代碼得到這個錯誤:
在函數'rapidjson :: GenericDocument,rapidjson :: MemoryPoolAllocator> :: GenericDocument(rapidjson :: GenericDocument,rapidjson :: MemoryPoolAllocator>常量&)':
../../rapidjson/document。 h:691:對`rapidjson ::的未定義引用在minilang中,rapidjson :: MemoryPoolAllocator> ::在minilang中(rapidjson ::在minilang中,rapidjson :: MemoryPoolAllocator>常量&)」 collect2:錯誤:LD返回1種退出狀態,如果我更改從參數類型
錯誤消失「 rapidjson :: Document jmsg「改爲」rapidjson :: Document & jmsg「。使用引用是好的,但是,如果我沒有將它定義爲引用類型,我仍然想知道代碼有什麼問題。
很高興見到你的左右。 ) – ArtemGr
這工作就像一個魅力!但是如何指針不起作用?我試着將'rapidjson :: Document * doc_ptr'傳遞給我的函數,並且一直抱怨'Document'不可訪問。 – benjaminz