功能代码:
std::set<OutputData> results;
OutputData od;
for (unsigned int qt = 0; qt < sizeof(allResultTypes); qt++)
{
//for each ResultType loop through all dates (Labels property)
for (unsigned int i = 0; i < sizeof(allDates[i]); i++)
{
//write date to the ExposureData object
od.date = JsonParser::allLabels[i];
if (allResultTypes[qt] == "type_A")
{
od.type_A = allData[i];
}
if (allResultTypes[qt] == "type_B")
{
od.type_B = allData[i];
}
results.insert(od);
}
}
输出数据类;
struct OutputData
{
int32_t date;
double type_A;
double type_B;
};
问题:
1)一旦将od插入到结果集中,我可以擦除od变量的内容吗?我想以这种方式重用od对象;
for (unsigned int i = 0; i < sizeof(allDates[i]); i++)
{
if (od != nullptr)
{
od.date = nullptr;
od.type_A = nullptr;
od.type_B = nullptr;
}
//write date to the ExposureData object
od.date = JsonParser::allLabels[i];
if (allResultTypes[qt] == "type_A")
{
od.type_A = allData[i];
}
if (allResultTypes[qt] == "type_B")
{
od.type_B = allData[i];
}
results.insert(od);
}
这是正确的还是我取消了前面循环迭代添加的set的内容?