我相信斯特劳斯图普的书,第三版第368页有一个错别字。有人可以确认吗?

I believe there is a typo in Stroustup's book, third edition page 368. Could someone confirm?

本文关键字:错别字 有一个 确认 368页 斯特劳斯 我相信 三版      更新时间:2023-10-16

我相信这段代码是从Stroustup的书中提取的,在368:页上有一个拼写错误

template <class X> class std::auto_ptr
{
    template <class Y> struct auto_ptr_ref { /* ... */ }; // helper class
    X * ptr;
    public :
    typedef X element_type;
    explicit auto_ptr(X* p =0) throw() { ptr = 0; }
    auto_ptr (auto_ptr& a) throw() { ptr = a.ptr; a.ptr = 0; } // note: not const auto_ptr&
    /* ... */
};

不应该

explicit auto_ptr(X* p =0) throw() { ptr = 0; }

explicit auto_ptr(X* p =0) throw() { ptr = p; }

相反?

本书的勘误表进行了一些更改:

第14章:

第367-368页最近标准的变化修改了auto_ptr的定义。请将第367页和第368页的最后一段。。。

我看过那本书,但我有一个新版本,它有一些额外的页面。

无论如何,该代码看起来是正确的,因为它说的是p=0,而说ptr=p与ptr=0是一样的。

相关文章: