Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Think of it this way. This is perfectly valid:</p> <pre><code>void Type::print_self () const { std::cout &lt;&lt; *this &lt;&lt; std::endl; } </code></pre> <p>You aren't modifying the object itself, so the use of the <code>const</code> qualifier is perfectly valid. This method is modifying <code>std::cout</code>, but that doesn't count as far as the <code>const</code>ness of <code>Type::print_self()</code> goes.</p> <p>That said, <code>mutable Cache</code> looks to me to be a contradiction in terms unless you are only using that <code>Cache</code> element for local storage within <code>Render</code>. If you are truly using it as a cache it seems a bit dubious to qualify this element as <code>mutable</code>. Use it as a cache (e.g., across calls to <code>Render</code> rather than within a call to <code>Render</code>) and you have lied to both the compiler and to the user of the class.</p> <p><strong>Edit</strong><br> Per the comments made by the OP, the <code>Render</code> method truly is the graphical equivalent of <code>print_self()</code>. The 'real' state of the object (presumably not shown for the sake of constructing a minimal working example) presumably isn't modified by rendering. Designating <code>Render</code> as a <code>const</code> method is the right thing to do. If the <code>Cache</code> data member reason for being is to serve as speed bump that avoids the cost of constructing and destructing it with each call to <code>Render</code> there is nothing wrong with qualifying that <code>Cache</code> member as <code>mutable</code> (which is needed so that <code>Render</code> can remain <code>const</code>).</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