fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class Item
  6. {
  7. public:
  8. virtual Item* clone() = 0;
  9. virtual ~Item() {}
  10. };
  11.  
  12.  
  13. class Ingredient : public Item
  14. {
  15. public:
  16. Ingredient()
  17. {
  18. std::cout<<"Hi\n";
  19. }
  20.  
  21. Ingredient(const Ingredient &other)
  22. {
  23. std::cout<<"Copied\n";
  24. }
  25.  
  26. virtual Ingredient* clone() override
  27. {
  28. return new Ingredient(*this);
  29. }
  30. };
  31.  
  32. int main() {
  33. Ingredient i;
  34.  
  35. Ingredient *j = i.clone();
  36. delete j;
  37. return 0;
  38. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Hi
Copied