fork download
  1. #include <iostream>
  2.  
  3. class Example {
  4. private:
  5. int a;
  6. // lots of important variables from the heap
  7. public:
  8. int getA() { return a; }
  9.  
  10. Example() {
  11. std::cout << "constructor" << std::endl;
  12. }
  13.  
  14. ~Example() {
  15. std::cout << "destructor" << std::endl;
  16. // we have no heap variables, but those would be deleted here
  17. }
  18. };
  19.  
  20. int main() {
  21. for (int i = 0; i < 5; i++) {
  22. Example e;
  23. // scope of e ends, so destructor is called
  24. }
  25. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
constructor
destructor
constructor
destructor
constructor
destructor
constructor
destructor
constructor
destructor