Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Furthermore, it doesn't seem make sense to typedef boost::shared_ptr during the declaration of Widget itself—we seem to be mixing Widget's declaration with an anticipation of how clients will make use of the Widget interface.</p> </blockquote> <p>First of all, this is not at all wrong - after all, the means of how the clients will (and can) use the interface <em>is</em> part of the interface itself; and for C++, not being garbage-collected, memory management of objects is a rather crucial part of their interface.</p> <p>So there are two cases. In one case, the <code>Widget</code> would anticipate it would be used through a shared pointer. This would mean that eg. child widgets obtained from a widget are returned as <code>shared_ptr</code>s, everywidget created has it <code>shared_ptr</code> and so on. It would be totally legitimate to typedef <code>WidgetPtr</code> in the same header as <code>Widget</code>.</p> <p>In the second case, <code>Widget</code>s would expect to be managed eg. by ordinary <code>new</code> and <code>delete</code>. The clients can use <code>shared_ptr</code>s in special cases, but nothing says eg. a printer dialogue routine can't use <code>auto_ptr</code> instead. The clients have to be prepared that if <code>wptr</code> is a <code>shared_ptr</code>, the line</p> <pre><code>shared_ptr&lt;Widget&gt; w2(wptr-&gt;firstChild()-&gt;parent()); </code></pre> <p>leads to a disaster.</p> <p>Your question seems to indicate the latter is your case. So IMHO, what you've done is OK. The clients can choose their means of managing <code>Widget</code> objects, as long as it doesn't affect other clients.</p>
    singulars
    1. This table or related slice is empty.
    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. 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