title: Controlled access to private member
body: <p>I have a class that contains a private std::vector and a flag. Every time an Object inside the vector is modified I want to set that flag.</p>
  <p>This is what I came up with..</p>
  <pre><code>struct Object
  {
      float f;
      int i;
  }
  
  class SomeClass
  {
  private:
      std::vector&lt;Object&gt; Data;
      bool Updated;
  
  public:
      inline const std::vector&lt;Object&gt;&amp; ReadData const
      {
          return Data;
      }
      inline std::vector&lt;Object&gt;&amp; WriteData
      {
          Updated = false;
          return Data;
      }
  }
  </code></pre>
  <p>This design is the safest I could come up with. The only issue with this is the fact I can bypass this safety mechanism when I'm using <code>Data</code> inside <code>SomeClass</code>.</p>
  <p>So, even though I don't have lots of methods in <code>SomeClass</code> that operate on <code>Data</code>, could you suggest me a better design to achieve this? (Tracking every change to <code>Data</code> by setting <code>Updated</code> accordingly)</p>