Note that there are some explanatory texts on larger screens.

plurals
  1. POPIMPL const correctness
    primarykey
    data
    text
    <p>.h</p> <pre><code>public: void doStuff() const; private: struct Private; Private * d; </code></pre> <p>.cpp</p> <pre><code>struct XX::Private { int count; } void XX::doStuff() const { d-&gt;count = 2; // I want an error here!! } </code></pre> <p>Do you need furher explanation?</p> <p>Update:</p> <p>I thought I'd do something a bit different that requires less changes to the code. I made this:</p> <p>.h</p> <pre><code>template &lt;class TPriv&gt; class PrivatePtr { public: ... TPriv * const operator-&gt;(); TPriv const * const operator-&gt;() const; ... private: TPriv * m_priv; }; </code></pre> <p>.cpp</p> <pre><code>... template &lt;class TPriv&gt; TPriv * const PrivatePtr&lt;TPriv&gt;::operator-&gt;() { return m_priv; } template &lt;class TPriv&gt; TPriv const * const PrivatePtr&lt;TPriv&gt;::operator-&gt;() const { return m_priv; } </code></pre> <p>And then use it like this:</p> <p>.h</p> <pre><code>#include &lt;PrivatePtr.h&gt; class DLLEXPORTMACROTHING myclass { ... private: struct Private; PrivatePtr&lt;Private&gt; d; }; </code></pre> <p>.cpp</p> <pre><code>#include &lt;PrivatePtr.cpp&gt; struct myclass::Private() { ... } </code></pre> <p>But this causes C4251 "myclass::d : class 'PrivatePtr' needs to have dll-interface to be used by clients of clas 'myclass'</p> <p>Wait, what? I DON'T want it to be used by anyone but myclass internally... safe to ignore? I tried looking for the answer but none of the cases were close to what I have here. On the other cases it did seems like quite a bit issue.</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.
 

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