More Effective c++ 之 auto_ptr

用auto_ptr 指向数组类型是有问题嘀!

 

#include <iostream>
#include <memory>
#include <string>

using namespace std;

int c= 0;

class X{
public:
X(): s("01234567879") {++c;}
~X() {--c;}

private:
string s;
};

template <class T>
void f(size_t n)
{
{
auto_ptr<T> p1(new T);
auto_ptr<T> p2(new T[n]);
}

cout<< c << "";
}

int main()
{
while (true)
f<X>(100);
}



posted @ 2011-11-19 18:52  maadiah  阅读(249)  评论(0编辑  收藏  举报