fork download
  1. #include <iostream>
  2. #include <boost/ptr_container/ptr_map.hpp>
  3.  
  4. struct Shape
  5. {
  6. virtual ~Shape() = 0;
  7. };
  8.  
  9. Shape::~Shape() {}
  10.  
  11. struct Triangle : Shape
  12. {
  13. };
  14.  
  15. struct Circle : Shape
  16. {
  17. };
  18.  
  19. int main()
  20. {
  21. boost::ptr_map<int, Shape> map;
  22.  
  23. int index = 0; // needed as insert takes key by non-const ref
  24. map.insert(index, new Triangle);
  25. index = 1;
  26. map.insert(index, new Circle);
  27.  
  28. if (map.find(0) != map.end())
  29. {
  30. std::cout << "found";
  31. }
  32. }
Success #stdin #stdout 0.02s 2860KB
stdin
Standard input is empty
stdout
found