Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Why the original reference of C++ does not include ownership

Shulou Source: shulou.com Published: 2022-06-01 19:21:51 09月13日 Update

This article mainly explains why the original citation of C++ does not include ownership. The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought. Let's study and learn why the original citation of C++ does not include ownership.

R.4: the original reference (T &) does not contain ownership Reason (reason)

There is no exception to this (whether in the C++ standard or in most of the code), and in fact most of the original references do not contain ownership. I want the owner to be identified so that we can reliably and efficiently delete the objects pointed to by the ownership pointer.

Example (sample)

Void f ()

{

Int& r = * new int {7}; / / bad: raw owning reference

/ /...

Delete & r; / / bad: violated the rule against deleting raw pointers

}

Thank you for your reading. The above is the content of "Why the original reference of C++ does not contain ownership". After the study of this article, I believe you have a deeper understanding of why the original reference of C++ does not include ownership. Specific use also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Ownership originality caching learning content that is code reason most actual actually object idea situation owner point pointer article more standard Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft Shulou Tech Info MariaDB Huawei