title: AddRef and function signature
body: <p>I've always used the following rule for signatures of functions that return ref-counted objects based on whether they do an AddRef or not, but want to explain it to my colleagues too... So my question is, is the rule described below a widely followed rule? I'm looking for pointers to (for example) coding rules that advocate this style.</p>
  
  <hr>
  
  <p>If the function does not add a reference to the object, it should be returned as the return value of the function:</p>
  
  <pre><code>class MyClass
  {
  protected:
      IUnknown *getObj() { return m_obj; }
  private:
      IUnknown *m_obj;
  };
  </code></pre>
  
  <p>However, if the function adds a reference to the object, then a pointer-to-pointer of the object is passed as a parameter to the function:</p>
  
  <pre><code>class MyClass
  {
  public:
      void getObj(IUnknown **outObj) { *outObj = m_obj; (*outObj)-&gt;AddRef(); }
  private:
      IUnknown *m_obj;
  };
  </code></pre>