Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>The method you declared is not <code>const</code>. It returns a <code>const void</code> (whatever that is), but it is not a <code>const</code>-method itself.</p></li> <li><p>If it were declared</p> <pre><code>void modify(float&amp; dummy) const </code></pre> <p>it would be a const-method, but then still it could modify the value of the argument, because a const-method is allowed to do this. The only thing it is not allowed to do is to modify values of members of the class it belongs to.</p></li> <li><p>Note that in order to declare a <code>const</code> method, I had to remove the <code>static</code> specification. A <code>static</code> method can never be <code>const</code>, because a static method can't modify any members anyway.</p></li> <li><p>If you want to prevent the function from modifying its argument, you'd have to make the argument const:</p> <pre><code>static void modify(const float&amp; dummy) </code></pre></li> </ol> <hr> <p>To illustrate what a const-method can and cannot do, here is a class that has a member, and a const-function:</p> <pre><code>class A { float my_member; public: void modify(float&amp; dummy) const { my_member = dummy; // attempt to modify member -&gt; illegal dummy = 1.5f; // modifies a non-const argument -&gt; ok } }; </code></pre> <p>As you can see, it cannot modify a member, but it can modify the value of its argument. If you want to prevent that, you need to make the argument <code>const</code>:</p> <pre><code>class A { float my_member; public: void modify(const float&amp; dummy) const { my_member = dummy; // attempt to modify member -&gt; illegal dummy = 1.5f; // attempt to modify a const reference -&gt; illegal } }; </code></pre>
    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