fork download
  1. #include <iostream>
  2.  
  3. class foo{
  4. static int idgen;
  5. protected:
  6. int id;
  7. public:
  8. foo(){
  9. id = idgen++;
  10. std::cout << "Hello ( foo - "<<id<<")"<<std::endl;
  11. }
  12. virtual ~foo(){
  13. std::cout << "Bye bye ( foo - "<<id<<")"<<std::endl;
  14. };
  15. };
  16.  
  17. int foo::idgen = 0;
  18.  
  19.  
  20. class bar: public foo{
  21. double some_data[20];
  22. public:
  23. bar(){
  24.  
  25. std::cout << "Hello ( bar - "<<id<<")"<<std::endl;
  26. }
  27. virtual ~bar() override{
  28. std::cout << "Bye bye ( bar - "<<id<<")"<<std::endl;
  29. }
  30. };
  31.  
  32. int main()
  33. {
  34. const unsigned int size = 2;
  35. foo* test = new bar[size];
  36. delete[] test;
  37. }
Runtime error #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
Hello  ( foo - 0)
Hello  ( bar - 0)
Hello  ( foo - 1)
Hello  ( bar - 1)