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);
}

原文链接: https://www.cnblogs.com/maadiah/archive/2011/11/19/2255431.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    More Effective c++ 之 auto_ptr

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/36807

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 下午1:31
下一篇 2023年2月8日 下午1:34

相关推荐