1
I have a list of objects from the No class, and would like to remove an object from that list, I use the library list
.
I know of the existence of pop_back()
and pop_front()
, but they delete exactly the first or last item from the list. In my case I will have a list of objects of this node class, and each object has its id, for example: No1(id=1),No2(id=2),No3(id=3),no4(id=4)...
I would like to remove id=2 for example, as I would?
Follow my class No.h:
#ifndef NO_H_INCLUDED
#define NO_H_INCLUDED
#include <list>
#include "Aresta.h"
using namespace std;
class No
{
int id;
list<Aresta> *adjNo;
public:
No(int id); // construtor
int getId();
list<Aresta>* getAdjNo();
void inserirAdj(Aresta aresta);
};
#endif // NO_H_INCLUDED
No cpp.:
#include "No.h"
#include <list>
No::No(int id){
this->id=id;
this->adjNo = new list<Aresta>;
}
int No::getId(){
return this->id;
}
list<Aresta>* No::getAdjNo(){
return this->adjNo;
}
void No::inserirAdj(Aresta aresta){
adjNo->push_back(aresta);
}
How would the function to carry out the exclusion?
void No::excluirNo(int id){
}
I simplified all my code so as not to pollute the question. I know of the existence of pop_back() and pop_front(), but they delete exactly the first or last item from the list. In my case I will have a list of objects of this node class, and each object has its id, for example: No1(id=1),No2(id=2),No3(id=3),no4(id=4)... I would like to remove id=2 for example, as I would do?
– Dudu Lopes
I know there is also remove in the list library, but I don’t know how to use since my parameter is a class, not an integer...
– Dudu Lopes
What you put in the question indicated that you wanted something else. And with what’s there I don’t even know what [and your real problem. I answered what I gave for what was asked. It is difficult to write one thing and want another.
– Maniero
I’m sorry if I wasn’t clear, with what I supplemented it is possible to help me with something ?
– Dudu Lopes