title: Best way to mutate a private vector in a class
body: <p>I have a question about better programming practice. Say, I have the following class:</p>
  
  <pre><code>class MyClass {
  public: 
      vector&lt;double&gt; data() { return data_; }
      void set_data(int index, double value) { data_[index] = value; }
  private:
      vector&lt;double&gt; data_;
  };
  </code></pre>
  
  <p>I have the private vector <code>data_</code> and accessor/mutator functions to that. Using <code>operator=</code> in case of public <code>data_</code> is very convenient. However, I need to make the <code>data_</code> private and access/mutate it through member functions. But I am not sure of the best way to construct the mutator function. The best way I have so far is the one in the example. Any suggestions?</p>