Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

智能指针小试

  • Loading branch information...
commit 048d038bb7f2607c2aaacad24266729350a081eb 1 parent f67571f
= authored
Showing with 10 additions and 1 deletion.
  1. +10 −1 shared_ptr.cpp
View
11 shared_ptr.cpp
@@ -1,5 +1,7 @@
// 智能指针小试
+
+
#include <iostream>
#include <string>
#include <boost/smart_ptr.hpp>
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.