title: Caching a const char * as a return type
body: <p>Was reading up a bit on my C++, and found this article about RTTI (Runtime Type Identification):
  <a href="http://msdn.microsoft.com/en-us/library/70ky2y6k(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/70ky2y6k(VS.80).aspx</a> . Well, that's another subject :) - However, I stumbled upon a weird saying in the <code>type_info</code>-class, namely about the <code>::name</code>-method. It says: "The <code>type_info::name</code> member function returns a <code>const char*</code> to a null-terminated string representing the human-readable name of the type. The memory pointed to is cached and should never be directly deallocated."</p>
  
  <p>How can you implement something like this yourself!? I've been struggling quite a bit with this exact problem often before, as I don't want to make a new <code>char</code>-array for the caller to delete, so I've stuck to <code>std::string</code> thus far.</p>
  
  <p>So, for the sake of simplicity, let's say I want to make a method that returns <code>"Hello World!"</code>, let's call it </p>
  
  <pre><code>const char *getHelloString() const;
  </code></pre>
  
  <p>Personally, I would make it somehow like this (Pseudo):</p>
  
  <pre><code>const char *getHelloString() const
  {
    char *returnVal = new char[13];
    strcpy("HelloWorld!", returnVal);
  
    return returnVal
  }
  </code></pre>
  
  <p>.. But this would mean that the caller should do a <code>delete[]</code> on my return pointer :(</p>
  
  <p>Thx in advance</p>