fork download
  1. #include <cstddef>
  2. #include <iostream>
  3.  
  4. struct Pig {
  5. Pig() {std::cout << this << " oinks!" << std::endl;}
  6. ~Pig() {std::cout << this << " is bacon!" << std::endl;}
  7. };
  8.  
  9. class PigFarm {
  10. public:
  11. explicit PigFarm(std::size_t n): sp(new Pig[n]) {throw "FARM FIRE!";}
  12. ~PigFarm() {delete[] sp;}
  13. private:
  14. Pig *sp;
  15. };
  16.  
  17. int main()
  18. {
  19. try {
  20. PigFarm pf(4);
  21. }
  22. catch (const char *pc) {
  23. std::cerr << pc << std::endl;
  24. }
  25. }
  26.  
Success #stdin #stdout 0.01s 2856KB
stdin
Standard input is empty
stdout
0x980400c oinks!
0x980400d oinks!
0x980400e oinks!
0x980400f oinks!