Quick actions

cmd+k|ctrl+k

Navigation

Languages

cpp/share_ptr

Snippet info

Language

Cpp

Visibility

public

Author

legacy-v1-32

Created

2017-01-10T07:59:54Z

Updated

2017-01-10T07:59:54Z

#include <stdio.h>
#include <iostream>
#include <tr1/memory>
#include <thread>
#include <chrono>
#include <mutex>

class A{
public:
    A(){
        std::cout<<"Construct A!"<<std::endl;
    };
    ~A(){
        std::cout<<"Destruct A!"<<std::endl;
    };
};

class B: public A {
public:
    B(){
        std::cout<<"Construct B!"<<std::endl;
    };
    ~B(){
        std::cout<<"Destruct B!"<<std::endl;
    };
};

int main(){
    
    B *b1 = new B();
    std::cout<<"-----------divid line--------"<<std::endl;
    std::tr1::shared_ptr<B> b2(new B());
    std::cout<<"-----------divid line--------"<<std::endl;
    // A a;
    std::cout<<"-----------divid line--------"<<std::endl;
    // std::tr1::shared_ptr<A> spa(new A());
    std::cout<<"-----------divid line--------"<<std::endl;
    return 0;
}
INFO