zoukankan      html  css  js  c++  java
  • 使用enable_shared_from_this示例

     1 /*测试enable_shared_from_this*/
     2 #include <iostream>
     3 #include <boost/smart_ptr/shared_ptr.hpp>
     4 #include <boost/smart_ptr/weak_ptr.hpp>
     5 #include <boost/smart_ptr/enable_shared_from_this.hpp>
     6 using namespace std;
     7 
     8 class TestClass : public enable_shared_from_this<TestClass>
     9 {
    10 public:
    11 private:
    12     int var;
    13 };
    14 
    15 void main()
    16 {
    17     TestClass *pobj = new TestClass();
    18 
    19     shared_ptr<TestClass> sptr(pobj);
    20     if (sptr==pobj->shared_from_this())
    21     {
    22         cout << "==" << endl;
    23     }
    24     else
    25     {
    26         cout << "!=" << endl;
    27     }
    28 
    29     shared_ptr<TestClass> sptr2;
    30     if (sptr2==pobj->shared_from_this())
    31     {
    32         cout << "==" << endl;
    33     }
    34     else
    35     {
    36         cout << "!=" << endl;
    37     }
    38 }
    煮酒论英雄
  • 相关阅读:
    设计模式——设计模式之禅day2
    和阿文一起学H5——音乐素材
    mysql数据库问题
    vue-cli脚手架工具
    webpack总结
    sql和nosql区别
    MongoDB基本命令
    >nbsp修改
    字典
    列表
  • 原文地址:https://www.cnblogs.com/superstargg/p/3711645.html
Copyright © 2011-2022 走看看