fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Object {
  5. private:
  6. int *_content;
  7. public:
  8. Object();
  9. ~Object();
  10. };
  11.  
  12. Object::Object() {
  13. cout << "Inside constructor.\n";
  14. _content = new int(5);
  15. return;
  16. }
  17.  
  18. Object::~Object() {
  19. cout << "Inside destructor.\n";
  20. delete _content;
  21. return;
  22. }
  23.  
  24. void doThing() {
  25. cout << "Inside doThing.\n";
  26. Object obj2;
  27. cout << "Exiting doThing.\n";
  28. }
  29.  
  30. int main() {
  31. cout << "Inside main.\n";
  32. cout << "Creating object.\n";
  33. Object obj;
  34. doThing();
  35. cout << "Ending function.\n";
  36. return 0;
  37. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Inside main.
Creating object.
Inside constructor.
Inside doThing.
Inside constructor.
Exiting doThing.
Inside destructor.
Ending function.
Inside destructor.