fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class A{
  6. int b;
  7. public:
  8. A(){
  9. cout<<"Constructor for class A called\n";
  10. b = 6;
  11. }
  12. ~A(){
  13. cout<<"Destructor called for class A\n";
  14. }
  15. };
  16.  
  17. class B{
  18. A a;
  19. public:
  20. B(){
  21. cout<<"Constructor for class B called\n";
  22. }
  23. ~B(){
  24. cout<<"Destructor called for class B\n";
  25. }
  26. };
  27.  
  28.  
  29. int main(void){
  30. B obj1;
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
Constructor for class A called
Constructor for class B called
Destructor called for class B
Destructor called for class A