weak_ptr constructor



#include <memory>
#include <iostream>
                                                                                                         
using std::weak_ptr,
    std::shared_ptr,
    std::make_shared,
    std::cerr;

class Temp{
    public:
        int a, b;
        Temp(int i = 1, int j = 1):a(i), b(j){}
};

int main(){
    weak_ptr<Temp> wp;
    weak_ptr<Temp> wp2(wp);
    shared_ptr<Temp> p1 = make_shared<Temp>();
    weak_ptr<Temp> wp3(p1);
    weak_ptr<Temp> wp4(move(wp3));

    return 0;
}      
C++ Examples© 2024 TBD