I am writing a program in c++ (for a list) where an element that is smaller than the one before is deleted. I declared 2 elements- current and next but i get declaration errors and have no idea why. I checked the syntax, it is correct.
My code:
#include <iostream>
#include <list>
using namespace std;
void deleteFromSTLList(list<int> &numbers) {
auto curr = numbers.begin();
auto next = ++numbers.begin();
while (next != numbers.end()) {
if (*curr < *next) {
next = numbers.erase(next);
continue;
}
curr = next;
next++;
}
}
I am getting an error that my variables curr and next ar not declared in this scope and do not name a type.
Aucun commentaire:
Enregistrer un commentaire