Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;rapidjson::Value的模板_C++_Templates_Rapidjson - Fatal编程技术网

C++ c++;rapidjson::Value的模板

C++ c++;rapidjson::Value的模板,c++,templates,rapidjson,C++,Templates,Rapidjson,我尝试创建模板,以便将数据设置为数组。我是这样做的: template <class T1> void SetArray(rapidjson::Document &JsonObj, std::string ArrayName, T1 value) { if (!JsonObj.IsObject()) JsonObj.SetObject(); rapidjson:

我尝试创建模板,以便将数据设置为数组。我是这样做的:

template <class T1>
        void SetArray(rapidjson::Document &JsonObj, std::string ArrayName, T1 value)
        {
            if (!JsonObj.IsObject())
                JsonObj.SetObject();


            rapidjson::Document::AllocatorType& alloc = JsonObj.GetAllocator();

            rapidjson::Value KeyPart;
            KeyPart.SetString(ArrayName.c_str(), alloc);

            rapidjson::Value ValuePart;
            ValuePart.SetString(value.c_str(), alloc);
}
模板
void SetArray(rapidjson::Document&JsonObj,std::string ArrayName,T1值)
{
如果(!JsonObj.IsObject())
JsonObj.SetObject();
rapidjson::Document::AllocatorType&alloc=JsonObj.GetAllocator();
rapidjson::值键部件;
KeyPart.SetString(ArrayName.c_str(),alloc);
rapidjson::Value-ValuePart;
ValuePart.SetString(value.c_str(),alloc);
}
我找不到如何通过T1来区分不同的值类型(std::string、int、bool等)
请帮忙,谢谢

rapidjson::Value构造函数已经为各种类型提供了重载,因此您只需这样做即可

rapidjson::Value ValuePart{value};

通常的方法是不使用SetArray模板,只使用常规重载函数。有时,SetArray可以是一个模板,它共享大部分实现,但对于特定于每种类型的部分,它可以不使用常规重载函数。