Advertisement
bogolyubskiyalexey

Untitled

Mar 23rd, 2021
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <memory>
  4.  
  5. class A {
  6. public:
  7.     A() {std::cout << "A::A()" << std::endl;}
  8.     virtual ~A() {std::cout << "A::~A()" << std::endl;}
  9.     virtual void f() {
  10.         std::cout << "A::f()" << std::endl;
  11.     }
  12. };
  13. class B : public A{
  14. public:
  15.     B() {std::cout << "B::B()" << std::endl;}
  16.     ~B() {std::cout << "B::~B()" << std::endl;}
  17.     void f() override {
  18.         std::cout << "B::f()" << std::endl;
  19.     }
  20. };
  21.  
  22.  
  23.  
  24.  
  25.  
  26. int main() {
  27.     {
  28.         A* b = new B;
  29.         b->f();
  30.         delete b;
  31.     }
  32.  
  33.     int* p4 = nullptr;
  34.     std::shared_ptr<int> p5;
  35.     {
  36.         std::shared_ptr<int> p(new int);
  37.         std::shared_ptr<int> p2;
  38.         p2 = p;
  39.         int* p3 = p2.get();
  40.         p4 = p2.get();
  41.         p5.swap(p2);
  42.     }
  43.     {
  44.         std::unique_ptr<int> p(new int);
  45.         std::unique_ptr<int> p2(p.get());
  46.        
  47.     }
  48.  
  49.  
  50.     //line
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement