从向量结构中删除元素

Erase elements from vector struct

所以我开始学习向量,我想从结构向量中删除一个元素,我把它作为结构:

typedef struct Carro{
   int id, cc, cv;
   char marca[50], modelo[50];
}car;

typedef struct Condutor{
   vector<car> cars;
   int id;
   int totalC=0;
   char nome[50];
}driver;

要删除的内容:

for(int i=0; i< (*ptr).size(); i++){
    if((*ptr)[i].id == id){
        (*ptr).erase((*ptr).begin +i);
        verif=true;
        break;
    }
    else{
        verif=false;
    }
}

但它似乎不起作用,因为我在尝试 运行 时在擦除行中遇到此错误:

invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator+'

如何从向量中删除一个元素?

在不知道 ptr 是什么的情况下,这是一个猜测,但您可能想要的不是:

  (*ptr).erase((*ptr).begin +i);

这个:

 ptr->erase( ptr->begin() +i);

begin() 是一个函数 - 您的代码试图将其视为函数指针。