title: Overloading ostream << operator returning address
body: <p>I am making a simple <em>Person</em> class which derives from Object.
  Each person has a name (char*).
  I would like to be able to print the name of the person using cout.
  I am not achieving the results desired.
  Here is my code:</p>
  
  <p>Person.h</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #ifndef _PERSON_H_
  #define _PERSON_H_
  using namespace std;
  
  class Object {};
  
  class Person : public Object {
  private:
      char* m_name;
  
  
  public:
      Person(char* input);
      ~Person();
      char* getName() const;
      //Set to friend because otherwise I was getting a compilation error.
      friend ostream&amp; operator&lt;&lt;(ostream&amp; os, const Person&amp; p);
  };
  
  
  
  #endif // _PERSON_H_
  </code></pre>
  
  <p>Person.cc</p>
  
  <pre><code>#include "Person.h"
  #include &lt;iostream&gt;
  #include &lt;cstring&gt;
  
  Person::Person(char* input) {
      m_name = new char[strlen(input)];
      strncpy(m_name, input, strlen(input));
  }
  
  char* Person::getName() const{
      return m_name;
  }
  
  /*Person&amp; Person::operator=(const Person &amp;rhs) {
      delete [] m_name;
      m_name = new char[strlen(rhs.getName())];
      strncpy(m_name, rhs.getName(), strlen(rhs.getName()));
      return *this;
  }*/
  
  ostream&amp; operator&lt;&lt;(ostream&amp; os, const Person&amp; p) {
      os &lt;&lt; p.getName();
      return os;
  }
  
  Person::~Person() {}
  
  int main() {
      char* tmp = "dave";
      Person * p = new Person(tmp);
      cout&lt;&lt;p;
  }
  </code></pre>
  
  <p>Output with the code above:</p>
  
  <pre><code>0x7fbba3c04b60
  </code></pre>
  
  <p>If I change the last line of the main to:</p>
  
  <pre><code>cout&lt;&lt;*p
  </code></pre>
  
  <p>I get the desired result, which is <em>dave</em>.</p>
  
  <p>My references:
  <a href="https://msdn.microsoft.com/en-us/library/1z2f6c2k.aspx" rel="nofollow" title="Microsoft Developer Network">Microsoft Developer Network</a></p>
  
  <p>How do I get <code>cout&lt;&lt;p</code> to print <code>dave</code>?</p>