fork download
  1. #include <iostream>
  2. #include <array>
  3. using namespace std;
  4.  
  5. struct A{
  6. int n=0;
  7. std::array<int,10000> arr;
  8. A(){
  9. cout<<"+A "<<this<<endl;
  10. }
  11. ~A(){
  12. for (int i=0;i<n;i++)
  13. cout<<arr[i]<<" ";
  14. cout<<endl;
  15. }
  16. void add(int r){
  17. cout<<"add "<<r<<endl;
  18. arr[n]=r;n=(n+1)%10000;
  19. }
  20. };
  21. int main(){
  22. {
  23. A* test=new A;
  24. test->~A();
  25. for (int i=0;i<10;i++){
  26. test->add(i*i);
  27. test->~A();
  28. }
  29. delete test;
  30. for (int i=0;i<10;i++){
  31. test->add(i*i);
  32. test->~A();
  33. }
  34. }
  35. }
  36.  
Runtime error #stdin #stdout 0s 4412KB
stdin
Standard input is empty
stdout
+A 0x55915cf64e70

add 0
0 
add 1
0 1 
add 4
0 1 4 
add 9
0 1 4 9 
add 16
0 1 4 9 16 
add 25
0 1 4 9 16 25 
add 36
0 1 4 9 16 25 36 
add 49
0 1 4 9 16 25 36 49 
add 64
0 1 4 9 16 25 36 49 64 
add 81
0 1 4 9 16 25 36 49 64 81 
0 1 4 9 16 25 36 49 64 81 
add 0