#include <cstdlib>
#include <iostream>
using namespace std;
#include <boost/scoped_ptr.hpp>
using namespace boost;
//scoped_ptr 和 auto_ptr 都是不允许被复制的
int main(int argc, char *argv[])
{
{
scoped_ptr<string> p(new string("Use scoped_ptr often."));
// 打印字符串的值
if(p)
cout << *p << '/n';
// 获取字符串的大小
size_t i = p->size();
cout<<i<<endl;
//scoped_ptr<string> p_another_scoped = p;//这句是编译不过的
// 给字符串赋新值
*p="Acts just like a pointer";
cout<<*p<<endl;
i = p->size();
cout<<i<<endl;
}//这里p被销毁,并删除std::string
system("PAUSE");
return EXIT_SUCCESS;
}
scoped_ptr 简单应用
最新推荐文章于 2019-09-01 09:53:26 发布