原生指针auto_ptr在头文件<memory>中,auto_ptr角括号内放的是“原生指针所指对象”的型别,

而不是原生指针的型别。

auto_ptr如下用法,和原生指针一模一样:

#include<iostream>
#include<string>
#include<memory>
using namespace std;

void func()
{
    auto_ptr<string> ps(new string("jjhou"));
    cout<<*ps<<endl;   //输出jjhou
    cout<<ps->size()<<endl; //输出5
}
int main()
{
    func();
    system("pause");
    return 0;
}

posted on 2013-04-26 10:04  吉大依恋  阅读(329)  评论(0编辑  收藏  举报