10 February 2023

C++ 核心指南目录

“A raw reference (a T&) is non-owning”

理由

大部分原始引用是无主的。我们希望明确引用的所有权,从而可以可靠、高效地删除对象。

例子

void f()
{
    int& r = *new int{7};  // bad: raw owning reference
    // ...
    delete &r;             // bad: violated the rule against deleting raw pointers
}