fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class One{
  5. int *ptr;
  6. public:
  7. One(unsigned long long size):ptr(new int[size])
  8. {
  9. std::cout<<__FUNCTION__<<endl;
  10. }
  11. ~One()
  12. {
  13. std::cout<<__FUNCTION__<<endl;
  14. if(ptr)
  15. delete[] ptr;
  16. }
  17. };
  18. class Two{
  19. int *ptr;
  20. public:
  21. Two(unsigned long long size): ptr(new int[size])
  22. {
  23. std::cout<<__FUNCTION__<<endl;
  24.  
  25. }
  26. ~Two()
  27. {
  28. std::cout<<__FUNCTION__<<endl;
  29. if(ptr)
  30. delete[] ptr;
  31. }
  32. };
  33.  
  34. class Wrapper{
  35. One one;
  36. Two two;
  37. public:
  38. Wrapper(unsigned long long s1, unsigned long long s2):
  39. one(s1), two(s2)
  40. {
  41. std::cout<<__FUNCTION__<<endl;
  42. }
  43. ~Wrapper()
  44. {
  45. std::cout<<__FUNCTION__<<endl;
  46. }
  47. };
  48. int main() {
  49. // your code goes here
  50. Wrapper *w = new Wrapper(1,0x7FFFFFFF);
  51. if (w) delete w;
  52. return 0;
  53. }
Runtime error #stdin #stdout #stderr 0s 4252KB
stdin
Standard input is empty
stdout
One
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc