KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In C++, when we use typeid to get type name of an object or class, it will show a decorated(mangled) string. I use cxxabi to demangle it: #include <cxxabi.h> #include <typeinfo> namespace MyNamespace { class MyBaseClass { public: const std::string name() { int status; char *realname = abi::__cxa_demangle(typeid (*this).name(),0,0, &status); std::string n = realname; free(realname); return n; } }; } int main() { MyNamespace::MyBaseClass h; std::cout << h.name() << std::endl; } The output in gcc is: MyNamespace::MyBaseClass I need to remove MyNamespace:: from above string. i can remove them by string manipulating . But is there a standard way with cxxabi or other libraries to do this or a clear solution? (At least portable between gcc and Visual C++)
Tags (comma-separated)
Save Edits
Cancel