Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Start by avoiding pointers.</p> <p>Use them when:</p> <ul> <li>You want to use the <a href="http://en.wikipedia.org/wiki/Opaque_pointer" rel="noreferrer">Pimpl idiom</a>, or an <a href="http://en.wikipedia.org/wiki/Abstract_factory_pattern" rel="noreferrer">abstract factory</a>.</li> <li>The <code>Bar</code> instance is actually managed by some other part of your program, whereas the <code>Foo</code> class just needs to be able to access it.</li> <li>You want to postpone the construction of the <code>Bar</code> object (i.e., you want to create it <em>after</em> constructing <code>Foo</code>).</li> <li>In your business logic, the <code>Bar</code> object may not exist at all; you would use <code>null</code> also in Java. However, check out <a href="http://www.boost.org/doc/libs/1_37_0/libs/optional/doc/html/index.html" rel="noreferrer">boost::optional</a> as well.</li> <li><code>Bar</code> is actually a base class, and you need the instance to be polymorphic.</li> <li>You happen to be using a toolkit that prefers to present GUI widgets as pointers. Examples could include (but are certainly not limited to) <a href="http://www.wxwidgets.org/" rel="noreferrer">wxWidgets</a> and <a href="http://www.cs.unc.edu/~rademach/glui/" rel="noreferrer">GLUI</a>.</li> </ul> <p>In any of these cases (*), start by using a smart pointer, such as <a href="http://www.boost.org/doc/libs/release/libs/smart_ptr/shared_ptr.htm" rel="noreferrer">boost::shared_ptr</a>. Otherwise, you are likely to forget to deallocate the memory, sooner or later. Once you know what you are doing, consider case-by-case what pointer type is best.</p> <p>(*) any case – except, probably, the bullet regarding GUI widgets; in this case, your toolkit would most probably manage the resources for you as well</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