title: In C++, is a const method returning a pointer to a non-const object considered bad practice?
body: <p>In C++, is a const method returning a pointer to a non-const object considered bad practice? For example. consider the following methods:</p>
  
  <pre><code>// Makes perfect sense
  bool isActive() const { return m_isActive; }
  
  // Makes perfect sense, both consts ensure nothing is modified
  const SomeObject* someObject() const { return m_someObject; }
  
  // Makes perfect sense, no const because SomeObject is mutable,
  // thus MyClass is indirectly mutable
  SomeObject* someObject() { return m_someObject; }
  
  // Makes no sense, if you're just returning a pointer to a const object,
  // then the method should clearly be const since nothing can be modified
  const SomeObject* someObject() { return m_someObject; }
  </code></pre>
  
  <p>The last combination puzzles me: is the following considered bad practice?</p>
  
  <pre><code>SomeObject* someObject() const { return m_someObject; }
  </code></pre>
  
  <p>Because the class that method returns is not const, but the method is, it is somewhat pointless since you could modify <code>SomeObject</code> and thus <em>indirectly</em> modify your class... so is that form considered bad practice? e.g. should you only use one of the following in place of it?</p>
  
  <pre><code>const SomeObject* someObject() const { return m_someObject; }
  SomeObject* someObject() { return m_someObject; }
  </code></pre>
  
  <hr>
  
  <p>Real-world situation: I'm writing a smartphone game which has a <code>Game</code> class. The <code>Game</code> class contains several methods which return pointers to utility classes like <code>InputManager</code>, <code>AudioManager</code>, etc.</p>
  
  <pre><code>class Game
  {
  public:
      InputManager* inputManager() const { return m_inputManager; }
      ...
  
  private:
      InputManager* m_inputManager;
      ...
  }
  </code></pre>
  
  <p>Does it make ANY sense at all to make <code>inputManager()</code> const, since the object it returns is not? (and should not be, since the <code>InputManager</code> needs to be mutable for its state to be updated, etc.)</p>
  
  <p>Or should I remove the method's <code>const</code> modifier to more accurately reflect the method's behavior? That way if I had a <code>const Game</code>, I couldn't call <code>inputManager()</code> and then mess with the <code>Game</code>'s input manager even though the <code>Game</code> was <code>const</code>.</p>