title: Conventions for accessor methods (getters and setters) in C++
body: <p>Several questions about accessor methods in C++ have been asked on SO, but none was able satisfy my curiosity on the issue.</p>
  
  <p>I try to avoid accessors whenever possible, because, like Stroustrup and other famous programmers, I consider a class with many of them a sign of bad OO. In C++, I can in most cases add more responsibility to a class or use the friend keyword to avoid them. Yet in some cases, you really need access to specific class members.</p>
  
  <p>There are several possibilities:</p>
  
  <p><strong>1. Don't use accessors at all</strong></p>
  
  <p>We can just make the respective member variables public. This is a no-go in Java, but seems to be OK with the C++ community. However, I'm a bit worried about cases were an explicit copy or a read-only (const) reference to an object should be returned, is that exaggerated?</p>
  
  <p><strong>2. Use Java-style get/set methods</strong></p>
  
  <p>I'm not sure if it's from Java at all, but I mean this:</p>
  
  <pre><code>int getAmount(); // Returns the amount
  void setAmount(int amount); // Sets the amount
  </code></pre>
  
  <p><strong>3. Use objective C-style get/set methods</strong></p>
  
  <p>This is a bit weird, but apparently increasingly common:</p>
  
  <pre><code>int amount(); // Returns the amount
  void amount(int amount); // Sets the amount
  </code></pre>
  
  <p>In order for that to work, you will have to find a different name for your member variable. Some people append an underscore, others prepend "m_". I don't like either.</p>
  
  <p>Which style do you use and why?</p>