提问人:Subhranil Dey 提问时间:3/26/2022 最后编辑:Subhranil Dey 更新时间:3/26/2022 访问量:349
push_back并插入向量不会向向量添加新元素 [duplicate]
push_back and insert for vectors doesn't add new elements to the vector [duplicate]
问:
我使用代码块,这个函数将 ShapePtr 添加到 ShapePtr 的向量不会向向量添加任何东西。
typedef Shape* ShapePtr;
void insertGrouped(vector<ShapePtr> arr, const ShapePtr &Sh)
{
int flag = 0;
if(arr.empty())
{
arr.push_back(Sh);
}
for(int i = 0; i < arr.size(); i++)
{
if(arr[i]->getType() == Sh->getType())
{
arr.insert(arr.begin() + i, Sh);
flag = 1;
break;
}
}
if(flag == 0)
arr.push_back(Sh);
}
答: 暂无答案
评论
vector<ShapePtr>& arr