title: C++ Structs with Member Functions vs. Classes with Public Variables
body: <p>This is really a question of good form/best practices. I use structs in C++ to form objects that are designed to basically hold data, rather than making a class with a ton of accessor methods that do nothing but get/set the values.  For example:</p>
  
  <pre><code>struct Person {
      std::string name;
      DateObject dob;
      (...)
  };
  </code></pre>
  
  <p>If you imagine 20 more variables there, writing this as a class with private members and 40-something accessors is a pain to manage and seems wasteful to me.</p>
  
  <p>Sometimes though, I might need to also add some sort of minimal functionality to the data.  In the example, say I also sometimes need the age, based on dob:</p>
  
  <pre><code>struct Person {
      std::string name;
      DateObject dob;
      (...)
      int age() {return calculated age from dob;}
  }
  </code></pre>
  
  <p>Of course for any complex functionality I would make a class, but for just a simple functionality like this, is this "bad design"?  If I do use a class, is it bad form to keep the data variables as public class members, or do I just need to accept it and make classes with a bunch of accessor methods?  I understand the differences between classes and structs, I'm just asking about best practices.</p>