Skip to content

Commit

Permalink
智能指针小试
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Dec 30, 2013
1 parent f67571f commit 048d038
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion shared_ptr.cpp
@@ -1,5 +1,7 @@
// 智能指针小试



#include <iostream>
#include <string>
#include <boost/smart_ptr.hpp>
Expand Down Expand Up @@ -34,8 +36,15 @@ int main(){
test_pc2->print_str(2);
std::cout<<"test_pc2 use_count = "<<test_pc2.use_count()<<std::endl;

boost::weak_ptr<TC> weak_pc = test_pc2;
std::cout<<"weak_pc use_count = "<<weak_pc.use_count()<<std::endl;
// 本以为也有 weak_pc->print_str(3)
// weak_ptr,没有重载->和* 呵呵, 也没有get(),呵呵呵
// Compared to shared_ptr, weak_ptr provides a very limited subset of operations
// http://www.boost.org/doc/libs/1_54_0/libs/smart_ptr/weak_ptr.htm

boost::shared_ptr<TC> test_pc3 = test_pc2;
test_pc3->print_str(3);
test_pc3->print_str(4);
std::cout<<"test_pc3 use_count = "<<test_pc3.use_count()<<std::endl;

return 0;
Expand Down

0 comments on commit 048d038

Please sign in to comment.