Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. struct Data {
  5. ~Data() {
  6. std::cout << "DATA DESTRUCTOR\n";
  7. }
  8. };
  9.  
  10. class A {
  11. public:
  12. // Try to switch between virtual/nonvirtual destructor and see what changes
  13. // virtual ~A() {
  14. ~A() {
  15. std::cout << "A DESTRUCTOR\n";
  16. }
  17. };
  18.  
  19. class B : public A {
  20. public:
  21. ~B() {
  22. std::cout << "B DESTRUCTOR\n";
  23. }
  24.  
  25. private:
  26. Data data_;
  27. };
  28.  
  29. int main() {
  30. int a = 0;
  31. std::cin >> a;
  32. const std::unique_ptr<A> ptr = a ? std::make_unique<B>() : std::make_unique<A>();
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement