1 shared_ptr    不明确的符号

boost的一些库,比如share_ptr已经被高版本的stl采纳了.如果在代码中没有指定命名空间,编译器就无法得知应该使用哪个命名空间之下的代码进行编译如下引入的命名空间的方式不推荐

using namespace std;

using namespace tr1;

using namespace boost;

实际上两个智能指针是一样的,你只需要用一个即可.如果你一定要两个都用,那么不要写上面的语句.而是应该写std::tr1::xxxx, boost:xxxx

2 shared_ptr 作为类成员函数的写法

#include <iostream>

#include <boost/shared_ptr.hpp>

struct SStudentInfo

{

public:

SStudentInfo()

{

std::cout << "Create instance" << std::endl;

};

~SStudentInfo()

{

std::cout << "Free instance" << std::endl;

}

};

class CTestSharedPtr

{

public:

CTestSharedPtr()

{

//m_student = new SStudentInfo();//error

m_student = boost::shared_ptr<SStudentInfo>(new SStudentInfo());

};

~CTestSharedPtr() {};

private:

boost::shared_ptr<SStudentInfo> m_student;

};

本文转自fengyuzaitu 51CTO博客,原文链接:http://blog.51cto.com/fengyuzaitu/1945834,如需转载请自行联系原作者

boost shared_ptr 用法相关推荐

  1. boost::shared_ptr用法测试程序

    boost::shared_ptr用法测试程序 实现功能 C++实现代码 实现功能 boost::shared_ptr用法测试程序 C++实现代码 #include <boost/config. ...

  2. boost学习之boost::shared_ptr

    Boost智能指针--shared_ptr boost::scoped_ptr虽然简单易用,但它不能共享所有权的特性却大大限制了其使用范围,而boost::shared_ptr可以解决这一局限.顾名思 ...

  3. boost::intrusive_ptr用法

    头文件: "boost/intrusive_ptr.hpp" intrusive_ptr 是shared_ptr的插入式版本.有时我们必须使用插入式的引用计数智能指针.典型的情况是 ...

  4. C++ shared_ptr用法、简析、案例

    shared_ptr用法 1 shared_ptr简介 2 shared_ptr案例 2.1 reset()的理解 2.2 make_shared的理解 2.3 shared_ptr中的指针转型问题 ...

  5. 初识boost之boost::share_ptr用法

    boost中提供了几种智能指针方法:scoped_ptr shared_ptr intrusive_ptr weak_ptr,而标准库中提供的智能指针为auto_ptr.  这其中,我最喜欢,使用最多 ...

  6. boost::shared_ptr相关的测试程序

    boost::shared_ptr相关的测试程序 实现功能 C++实现代码 实现功能 boost::shared_ptr相关的测试程序 C++实现代码 #include <boost/confi ...

  7. boost::lexical_cast用法的测试程序

    boost::lexical_cast用法的测试程序 实现功能 C++实现代码 实现功能 boost::lexical_cast用法的测试程序 C++实现代码 #include <boost/m ...

  8. boost::make_iterator_range用法的测试程序

    boost::make_iterator_range用法的测试程序 实现功能 C++实现代码 实现功能 boost::make_iterator_range用法的测试程序 C++实现代码 #inclu ...

  9. boost::transform_iterator用法的测试程序

    boost::transform_iterator用法的测试程序 实现功能 C++实现代码 实现功能 boost::transform_iterator用法的测试程序 C++实现代码 #include ...

  10. boost::advance用法的测试程序

    boost::advance用法的测试程序 实现功能 C++实现代码 实现功能 boost::advance用法的测试程序 C++实现代码 #include <vector> #inclu ...

最新文章

  1. SSM-SpringMVC-16:SpringMVC中小论注解式开发之访问方式篇
  2. Postgresql死锁的处理
  3. c语言补全 subilme_Sublime Text3 C语言插件
  4. 在c++代码中关闭和启动另外一个pid进程号,共享内存数据使用
  5. python返回菜单_返回上一菜单
  6. [虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(三)
  7. DMA访问(直接内存访问)
  8. ABP框架 - 授权
  9. MySQL数据库基础
  10. 单片机实验报告-片内外RAM的数据转移
  11. Lodop+html+pdf.js 实现web客户端连接的本地打印机直接打印,无需预览
  12. win10升级助手_详解win7升级win10系统方法
  13. zzulioj.1055 兔子繁殖问题
  14. 网站开发进阶(二十六)js刷新页面方法大全
  15. 【架构师】零基础到精通——网关详解
  16. 回望2018,这6家AI+教育公司亮了!| AI最佳掘金案例榜...
  17. 从原子结构,半导体,PN结到MOS管和CMOS
  18. 感悟人生的伤感日志_带着眼泪去流浪
  19. Linux获取当前目录名,shell获取当前目录名
  20. 红外通信的应用——PPM调制与解码(C51)

热门文章

  1. 微信小程序开发--【APP(Object)函数介绍】(三)
  2. android问题:Installation error: INSTALL_FAILED_CONFLICTING_PROVIDER
  3. ant接口用什么天线_拆解测量真假钻石手台天线SRH805S
  4. Ubuntu 问题合集
  5. 滴滴android面试算法,滴滴打车面试经验
  6. openoffice 64_科学网—四棱的核桃:卡片机傻拍2020(64)
  7. login.html id=9453,我关注的官网.html
  8. python 实现两个excel表格数据的对比--代码
  9. 记一次物理服务器Linux系统中未找到网卡的处理方式
  10. scp创建远程目录_如何在 HPC 硬件上远程运行大型仿真?