Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you're asking is not really possible.</p> <p>The <strong>only</strong> way to prevent something from being assigned is to define the <code>operator =</code> for that type as <code>private</code>. (As an extension of this, since const <code>operator =</code> methods don't make much sense (and are thus uncommon) you can come close to this by only allowing access to const references from your container. But the user can still define a const <code>operator =</code>, and you want mutable objects anyways.)</p> <p>If you think about it, <code>std::vector::operator []</code> returns a reference to the value it contains. Using the assignment operator will call <code>operator =</code> for the value. <code>std::vector</code> is completely bypassed here (except for the <code>operator[]</code> call used to get the reference in the first place) so there is no possibility for it (<code>std::vector</code>) to in any way to override the call to the <code>operator =</code> function. </p> <p>Anything you do to directly access the members of an object in the container is going to have to return a reference to the object, which can then be used to call the object's <code>operator =</code>. So, there is no way a container can prevent objects inside of it from being assigned unless the container implements a proxy for the objects it contains which has a private assignment operator that does nothing and forwards other calls to the "real" object, but does not allow direct access to the real object (though if it made sense to do so, you could return copies of the real object). </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. 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