title: C++ Why should I use get and set functions when working with classes
body: <p>I've been told not to make my variables public inside a class. I should always make a get and a set function. For example :</p>
  
  <pre><code>class Whatever
  {
  
  public:
    void setSentence(const std::string &amp;str) { sentence = str; }
    void setAnInteger(const int integer) { anInteger = integer; }
  
    std::string getSentence() { return sentence; }
    int getAnInteger() { return anInteger; }
  
  private:
    std::string sentence;
    int anInteger;
  
  };
  </code></pre>
  
  <p>Why should I do that? Isn't just simply using those variables more convenient? Also, is that a good c++ programming style?</p>