fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <memory>
  4.  
  5. struct Other
  6. {
  7. virtual void print() = 0;
  8. virtual ~Other() = default;
  9. };
  10.  
  11. struct Base
  12. {
  13. Base(Other *o)
  14. {
  15. o->print();
  16. }
  17. virtual ~Base() = default;
  18. };
  19. struct Derived : Base
  20. {
  21. Derived();
  22. virtual ~Derived();
  23. private:
  24. struct My;
  25. std::unique_ptr<My> my;
  26. };
  27.  
  28. int main()
  29. {
  30. Derived d;
  31. }
  32.  
  33. struct Derived::My : Other
  34. {
  35. std::string s = "It works";
  36. virtual void print()
  37. {
  38. std::cout << s << std::endl;
  39. }
  40. };
  41. Derived::Derived()
  42. : my(new My)
  43. , Base(my.get())
  44. {
  45. }
  46. Derived::~Derived() = default;
  47.  
Runtime error #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout

Standard output is empty