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;
} | 
Partager