Bonjour,

Voici un bout de code qui plante: la boucle for fait 4 itérations au lieu de 3 et forcement le programme plante!
Le compilateur est MinGW et le problème apparait avec la libstdc++.
Avec la STLPort 5.1 tout se passe bien...
Je voudrais savoir si le crash est du à une mauvaise utilisation ou à la libstdc++ !!

Merci!!!!

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
#include <windows.h>
#include <iostream>
#include <fstream>
#include <string>
#include <map>
 
 
class Object
{
  private:
    int Id;
    std::string Name;
  public:
    std::string getName(void) { return Name; }
    int getId(void) { return Id; }
    Object(const int i, const std::string& n) { Name = n; Id = i;}
};
 
int main(int argc, char* argv[], char* argenv[])
{
  std::map<int,Object*> Objects;
  Objects.insert(std::pair<int,Object*>(1,new Object(1, "Un")));
  Objects.insert(std::pair<int,Object*>(2,new Object(2, "Deux")));
  Objects.insert(std::pair<int,Object*>(3,new Object(3, "Trois")));
  std::map<int,Object*>::iterator it;
  for (it=Objects.begin(); it!=Objects.end(); ++it)
  {
    std::cout<<"Size=Objects.size()"<<std::endl;
    Object* obj = it->second;
    std::cout<<obj->getId()<<std::endl;
    //std::cout<<obj->getName()<<std::endl;
    delete obj;
    Objects.erase(it);
  }
 
  return EXIT_SUCCESS;
}