fork download
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4.  
  5. struct Foo
  6. {
  7. Foo() { cout << "*"; }
  8. ~Foo() { cout << "@"; }
  9. Foo(const Foo&) { cout << "="; }
  10.  
  11. };
  12.  
  13. int main() {
  14. // your code goes here
  15.  
  16. cout << "construct:";
  17. Foo *foo = new Foo[5];
  18. cout << endl;
  19.  
  20. int *p = new int;
  21. cout << "int: " << *p << endl;
  22. delete p;
  23.  
  24. int *n = new int[5];
  25. for (int i = 0; i < 5; i++)
  26. cout << n[i] << " ";
  27. cout << endl;
  28. delete [] n;
  29.  
  30. cout << "destruct:";
  31. delete [] foo;
  32. cout << endl;
  33.  
  34.  
  35. cout << "************" << endl;
  36.  
  37. allocator<Foo> allo;
  38.  
  39. Foo *a;
  40. Foo b;
  41.  
  42. cout << endl << "+++" << endl;
  43.  
  44. a = allo.allocate(5);
  45.  
  46. //new ((void*)(a+2)) Foo(b);
  47.  
  48. allo.construct(a, b); cout << endl;
  49.  
  50. cout << "fo" << endl;
  51.  
  52. allo.destroy(a);
  53.  
  54. allo.deallocate(a, 0); cout << endl;
  55.  
  56. cout << "************" << endl;
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
construct:*****
int: 0
0 0 0 0 0 
destruct:@@@@@
************
*
+++
=
fo
@
************
@