title: Removing namespace of type name in C++
body: <p>In C++, when we use <code>typeid</code> to get type name of an object or class, it will show a decorated(mangled) string. I use <code>cxxabi</code> to demangle it:</p>
  
  <pre><code>#include &lt;cxxabi.h&gt;
  #include &lt;typeinfo&gt;
  
  namespace MyNamespace {
  
  class MyBaseClass
  {
  public:
      const std::string name()
      {
          int status;
          char *realname = abi::__cxa_demangle(typeid (*this).name(),0,0, &amp;status);
          std::string n = realname;
          free(realname);
          return n;
      }
  };
  
  }
  
  int main()
  {
      MyNamespace::MyBaseClass h;
      std::cout &lt;&lt; h.name() &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>The output in <code>gcc</code> is:</p>
  
  <blockquote>
    <p>MyNamespace::MyBaseClass</p>
  </blockquote>
  
  <p>I need to remove <code>MyNamespace::</code> from above string. <strike><em>i can remove them by string manipulating</em> </strike>.</p>
  
  <p><strike>But</strike> is there a standard way with <code>cxxabi</code> or other libraries to do this or a clear solution?<em>(At least portable between gcc and Visual C++)</em></p>