Ok, i'm working on a very simple project but when it comes to implementing the methode advance to increment the iterator current, it doesnt work and says list iterator not incrementable, heres the code:
void liste::avancer()
{
courant++;
}
and heres the constructor one:
liste::liste(void)
{
courant = maliste.begin();
}
when i call the 'avancer' method from the main i have an error: list iterator not incrementable
It might be a good idea to post the smallest and simplest program that you expect to compile, but which demonstrates the problem.
liste.h
#pragma once
#include<list>
#include<iostream>
using namespace std;
class liste
{
list<int> maliste;
list<int>::iterator courant;
public:
liste(void);
void inserer();
void avancer();
void show();
~liste(void);
};
liste.cpp
#include "liste.h"
#include<iterator>
liste::liste(void)
{
courant = maliste.begin(); // to set the pointer on the begining of my list
}
liste::~liste(void)
{
}
void liste::show()
{
for (courant=maliste.begin(); courant!=maliste.end(); courant++) // to show my list
cout << " " << *courant ;
}
void liste::inserer()
{
insert_iterator<list<int>> it(maliste,maliste.begin()); // to insert an element
*it = 2;
}
void liste::avancer()
{
advance(courant,1); // or courant++ : both methods dont work!
}
run.cpp
#include"liste.h"
void main ()
{
liste a;
a.inserer(); // i insert 2 times the value 2
a.inserer();
a.avancer(); // here i want to increment the current iterator but it doesnt work
system("pause");
}
Bookmarks