长话短说:如何将rapidjson::Object
传递给方法?
详细说明:我有以下代码:
void CMyClass::SomeMethod()
{
rapidjson::Document doc;
doc.Parse(data.c_str(), data.size());
std::string output{};
for (const auto& obj : doc.GetObj())
{
if ("My_data" == obj.name)
{
ReadMyData(obj, output);
continue;
}
}
}
void CMyClass::ReadMyData(???, std::string& output)
{
//
}
字符串
我试过:
// header
template<bool Flag, typename T>
void ReadMyData(const rapidjson::GenericObject<Flag, T>& obj, std::string& output);
// implementation
template<bool Flag, typename T>
void CMyClass::ReadMyData(const rapidjson::GenericObject<Flag, T>& obj, SWeather& output)
{
}
型
但我得到了
.cpp(109): error C2672: 'CMyClass::ReadMyData': no matching overloaded function found
.cpp(109): error C2784: 'void CMyClass::ReadMyData(const rapidjson::GenericObject<Const,ValueT> &,std::string &)': could not deduce template argument for 'const rapidjson::GenericObject<Const,ValueT> &' from 'const rapidjson::GenericMember<Encoding,Allocator>'
1> with
1> [
1> Encoding=rapidjson::UTF8<char>,
1> Allocator=rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>
1> ]
型
更多信息:GetObj()
,是:
Object GetObj() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); }
型
而Object
是
template <typename Encoding, typename Allocator = RAPIDJSON_DEFAULT_ALLOCATOR >
class GenericValue {
public:
//! Name-value pair in an object.
typedef GenericMember<Encoding, Allocator> Member;
typedef Encoding EncodingType; //!< Encoding type from template parameter.
typedef Allocator AllocatorType; //!< Allocator type from template parameter.
typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding.
typedef GenericStringRef<Ch> StringRefType; //!< Reference to a constant string
typedef typename GenericMemberIterator<false,Encoding,Allocator>::Iterator MemberIterator; //!< Member iterator for iterating in object.
typedef typename GenericMemberIterator<true,Encoding,Allocator>::Iterator ConstMemberIterator; //!< Constant member iterator for iterating in object.
typedef GenericValue* ValueIterator; //!< Value iterator for iterating in array.
typedef const GenericValue* ConstValueIterator; //!< Constant value iterator for iterating in array.
typedef GenericValue<Encoding, Allocator> ValueType; //!< Value type of itself.
typedef GenericArray<false, ValueType> Array;
typedef GenericArray<true, ValueType> ConstArray;
typedef GenericObject<false, ValueType> Object;
typedef GenericObject<true, ValueType> ConstObject;
型
在rapidjson
命名空间中。
1条答案
按热度按时间vwoqyblh1#
迭代一个对象返回一个
GenericMember
而不是GenericObject
,你需要:字符串
除非您需要能够科普其他编码,否则可以将
ReadMyData
更改为非模板,而仅将rapidjson::Value::Object
作为obj参数