How to get class name?
问题 If I defined a class: class Blah {}; How can I: std::string const className = /* What do I need to do here? */; assert( className == "Blah" ); I dont think typeid().name() is a good idea since it's compiler implementation specific. Is there anything provided by the C++ standard or Boost? Note: If the class were inherited from Qt's QObject, I could easily use QMetaObject::className() to get the class name. 回答1: Like this: class Blah { static std::string const className() { return "Blah"; }};