shared_ptr2 boost::shared_ptr 주의 : shared_ptr형은 "shared_ptr이 아닌 데이터형"의 주소를 복사할 수 없다. 왜냐하면, shared_ptr은 참조 횟수가 0일때 자동으로 메모리를 해제하게 되는데, 만약 해제할 메모리가 자기가 관리하는 영역밖의 것이라면 안정성을 보장할 수 없기 때문이다. 아래와 같은 것이 안된다는 것이다. (잘못된 예) int a = 3; boost::shared_ptr test; test = &a // Compile error 대입 자체가 안된다. 대입은 shared_ptr끼리만 된다. (*test)++; 주석에 쓴 것처럼 shared_ptr끼리의 주소 대입은 된다. shared_ptr중 적어도 한개는 내부에 메모리를 할당한 object를 가지고 있어야 하기 때문에, 결국 shared_ptr끼리 .. 2008. 10. 8. boost::enable_shared_from_this class 의 member function에서 현재 object를 shared_ptr로 리턴하고자 할때 이것을 사용한다. (ex) class SharedClass : public boost::enable_shared_from_this { public: shared_ptr returnObject() { return shared_from_this(); } }; 2008. 10. 1. 이전 1 다음