我有此功能,以id表示的学生将在特定学期添加一门课程。这段代码是正确的,但是我不明白他什么时候做的
for (size_t i = 0; i < (*iteratorVectorP).size(); i++) ...
void add_course(map<int, map<int, vector<course *> * > > &DB, int
semester, int id, course c)
{
auto iterator = DB.find(id); //find id as key, set map to value
vector<course*> *pointer = new vector<course*>;
if (iterator != DB.end())
{
auto iterator1 = ((*iterator).second).find(semester); //find
semester as key, set vector to value
if (iterator1 == (*iterator).second.end()) //if semester does not exist
{
pointer->push_back(new course(c));
(iterator->second)[semester] = pointer;
}
else //if semester exist
{
auto iteratorVectorP = (iterator->second)[semester];
// i do not understand what his doing here
for (size_t i = 0; i < (*iteratorVectorP).size(); i++)
{
if (c == *(*iteratorVectorP)[i])
{
return; //exit when class exist
}
else
{
(*iteratorVectorP).push_back(new course(c));
return;
}
}
}
}
}
答案 0 :(得分:0)
iteratorVectorP的定义是向量,因此for循环正在迭代该过程,并尝试将其添加到向量中(如果不存在)。
答案 1 :(得分:0)
看起来iteratorVectorP是一个指针,因此调用(* iteratorVectorP).size()将获得它指向的值。