<table><tr><td style="">bruns added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D12145">View Revision</a></tr></table><br /><div><div><p>The first question is - why should we use pointers at all (raw, std::unique_ptr, QScopedPointer, ...) for objects <strong>with local only scope</strong>.</p>

<p>The typical answer is Inheritance, see e.g. <a href="http://doc.qt.io/qt-5/qscopedpointer.html#details" class="remarkup-link" target="_blank" rel="noreferrer">http://doc.qt.io/qt-5/qscopedpointer.html#details</a><br />
A <tt style="background: #ebebeb; font-size: 13px;">Base</tt> pointer can be used to hold an instance of <tt style="background: #ebebeb; font-size: 13px;">Base</tt>, <tt style="background: #ebebeb; font-size: 13px;">DerivedA</tt> or <tt style="background: #ebebeb; font-size: 13px;">DerivedB</tt>.</p>

<p>If the exact <strong>type is known and the object has local scope</strong>, I don't know <strong>any</strong> reason to allocate the object on the heap. Allocating on the heap is just pointless overhead.</p>

<p>Even when the <strong>scope is not local</strong>, but the type is known, it is often useful to allocate the object on the stack and extend its scope using the constructor. This applies to any d-pointer classes, where the copy constructur is hardly more expensive than a move constructor (all of Qts implicitly shared classes), or where we have a move constructor in the first place.</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R286 KFileMetaData</div></div></div><br /><div><strong>BRANCH</strong><div><div>plugin-simple (branched from master)</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D12145">https://phabricator.kde.org/D12145</a></div></div><br /><div><strong>To: </strong>michaelh, Baloo, Frameworks, mgallien, bruns<br /><strong>Cc: </strong>alexeymin, ashaposhnikov, michaelh, astippich, spoorun, ngraham, bruns<br /></div>