Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <memory>
- class A {
- public:
- A() {std::cout << "A::A()" << std::endl;}
- virtual ~A() {std::cout << "A::~A()" << std::endl;}
- virtual void f() {
- std::cout << "A::f()" << std::endl;
- }
- };
- class B : public A{
- public:
- B() {std::cout << "B::B()" << std::endl;}
- ~B() {std::cout << "B::~B()" << std::endl;}
- void f() override {
- std::cout << "B::f()" << std::endl;
- }
- };
- int main() {
- {
- A* b = new B;
- b->f();
- delete b;
- }
- int* p4 = nullptr;
- std::shared_ptr<int> p5;
- {
- std::shared_ptr<int> p(new int);
- std::shared_ptr<int> p2;
- p2 = p;
- int* p3 = p2.get();
- p4 = p2.get();
- p5.swap(p2);
- }
- {
- std::unique_ptr<int> p(new int);
- std::unique_ptr<int> p2(p.get());
- }
- //line
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement