'Developer/Design Patterns'에 해당되는 글 27건

  1. 2014.05.18 Strong Pointer & Weak Pointer

//weak ptr : 참조 계수가 없는 스마트 포인터

 

#include <iostream>

#include <memory>

using namespace std;

 

struct Node {

        int data;

        weak_ptr<Node> next;

 

        ~Node() { cout << "노드 파괴" << endl; }

};

 

int main() {

        shared_ptr<Node> p1(new Node);

        shared_ptr<Node> p2(new Node);

 

        p1->next=p2;

        p2->next=p1;

 

        return 0;

}

Posted by No names
,