rapidjson::Document in std::pair

rapidjson::Document in std::pair

本文关键字:pair std Document rapidjson in      更新时间:2023-10-16

我收到此错误:

Undefined symbols for architecture i386:
rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::GenericValue(rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> > const&)

当我尝试成对返回rapidjson::Document时,此错误会跳到我身上:

typedef std::pair<rapidjson::Document, std::string> ProcessedResponseResult;
ProcessedResponseResult ProcessResponse(HttpResponse* response)
{
    rapidjson::Document jsonDoc;
    ...
    return ProcessedResponseResult(jsonDoc, std::string());
}

如果有帮助,rapidjson 是一个仅标头库。

为什么我不能退回这对?

当你构造一个ProcessedResponseResult时,它会调用rapidjson::Document的复制构造函数,但在文件rapidjason/document.h中,为了防止复制rapidjson::Document对象,它声明了一个私有复制构造函数,并且不实现它,所以这会导致链接器错误。

//! Copy constructor is not permitted.
private:
    GenericValue(const GenericValue& rhs);

如果您使用 std::pair 的原因只是从函数返回 2 个值,我建议您通过引用传递jsonDoc