Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As they are data fields that can be modified, they are not <code>const</code>.</p> <p>If you want to restrict post-construct access to them to <code>const</code>, you need to wrap them in accessors as follows:</p> <pre><code>struct ImageInfo { ImageInfo(const double &amp;ppix, /*...*/) : PpiX_(ppix), /*...*/ { } double const&amp; PpiX() const {return PpiX_; }; double const&amp; PpiY() const {return PipY_; }; int const&amp; SizeX() const {return SizeX_; }; int const&amp; SizeY() const {return SizeY_; }; private: double PpiX_; double PpiY_; int SizeX_; int SizeY_; }; </code></pre> <p>That allows move/copy assignment and construction, while blocking non-<code>const</code> access outside of said construction.</p> <p>Avoiding the <code>()</code> is tricky, but could be done with pseudo-references, something like this:</p> <pre><code>struct pseudo_const_reference_to_Ppix { ImageInfo const* self; operator double() const { return self-&gt;Ppix; } void reseat( ImageInfo const* o ) { self = o; } }; </code></pre> <p>plus a whole pile of boilerplate to overload every <code>const</code> operator on the left and right such that the above <code>pseudo_const_reference_*</code> is just as valid as <code>double</code>.</p> <p>Generic versions can be written (either taking a functor or a <code>std::function</code> if you are willing to suffer type erasure overhead).</p> <p>Then you maintain these pseudo-<code>const</code> references on assignment and copy/move construction.</p> <p>I think the <code>()</code> is the better option.</p> <p>Note that the overhead of a pointer (or more) per pseudo-reference is basically unavoidable: member variables do not have access to the <code>this</code> from which they are invoked, even though the accesing site has it right there plain as day.</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. This table or related slice is empty.
    1. 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