fork download
  1. #include <memory>
  2. #include <iostream>
  3.  
  4. struct Die {
  5. ~Die () {
  6. std:: cout << "dead" << std::endl;
  7. }
  8. };
  9.  
  10. union Devil {
  11. std::unique_ptr<Die> ptr;
  12. Devil () {
  13. // initialise that later
  14. }
  15. ~Devil() {
  16. // .. No idea what I'm doing
  17. }
  18. int b;
  19. };
  20.  
  21. int main () {
  22. // ...
  23. Devil in_detail;
  24. in_detail.ptr = std::make_unique<Die>();
  25. in_detail.b = 42;
  26. }
Success #stdin #stdout 0s 3408KB
stdin
Standard input is empty
stdout
Standard output is empty