Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best way to solve this problem is to use a shared-ownership smart pointer like <code>shared_ptr</code>, which you can find in Boost, C++ TR1, and C++0x.</p> <p>A smart pointer is a container that manages the lifetime of your dynamically allocated object for you. It takes responsibility for <code>delete</code>ing the object when you are done using it.</p> <p>With a shared ownership smart pointer, you can have multiple smart pointers that all share ownership of the dynamically allocated object. A reference count is kept that keeps track of how many smart pointers have ownership of the object, and when the last owning smart pointer is destroyed, the dynamically allocated object is <code>delete</code>d.</p> <p>It is extremely difficult to manage resources manually in C++, and it's very easy to write code that looks correct and works right most of the time but that is still not correct. By using smart pointers and other resource-owning containers (like the standard library containers), you no longer have to manage resource manually. It is significantly easier to write correct code when all of your resource management is automatic.</p> <p>Automatic resource management in C++ is accomplished using a design pattern called <a href="http://jalf.dk/blog/2010/01/the-meaning-of-raii-or-why-you-never-need-to-worry-about-resource-management-again/" rel="nofollow">Resource Acquisition is Initialization (RAII)</a>, which is arguably the most important design pattern you as a C++ programmer should become familiar with. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload