fork download
  1. #include<iostream>
  2. using namespace std;
  3. class Point {
  4. public:
  5.  
  6. // Constructor
  7. // called whenever we create an object or instantiate an object
  8. // allocating memory
  9. Point() { cout << "Constructor called"<<endl; }
  10.  
  11. // Destructor
  12. // called whenever we delete an object or an object gets automatically deleted (garbage collection)
  13. // free the allocated memory
  14. ~Point() {
  15. cout<<"Destructor called"<<endl;
  16. }
  17.  
  18. };
  19.  
  20. int main()
  21. {
  22. // t1 is actually an object created and instantiated
  23. // t2 is a pointer to the object of the class and it aint yet instantiated
  24. Point t1, *t2;
  25. // allocated memory to our object pointer
  26. t2 = new Point();
  27. delete t2;
  28. return 0;
  29. }
Success #stdin #stdout 0s 5648KB
stdin
Standard input is empty
stdout
Constructor called
Constructor called
Destructor called
Destructor called