这应该比较容易,标准 C++ 有一个 type_info 类。这包含 typeid 的类/函数/等的名称。但它被破坏了。它不是很有用。即 typeid(std::vector<int>).name() 返回St6vectorIiSaIiEE。 有没有办法从中产生有用的东西?就像 std::vector<int> 上面的例子。如果它只适用于非模板类,那也没关系。 该解决方案应该...
#include <boost/core/demangle.hpp> #include <cstdlib> #include <iostream> #include <string> #include <typeinfo> struct Base { virtual ~Base() = default; }; struct Derived : Base {}; int main() { Base b1; Derived d1; const Base* pb = &b1; std::cout << typeid(*pb).name() ...
解开std :: type_info :: name的结果 我目前正在研究一些日志代码,它们应该 - 除其他外 - 打印有关调用函数的信息。这应该相对容易,标准C ++有一个type_info类。它包含typeid'd类/函数/ etc的名称。但它被破坏了。它不是很有用。即typeid(std::vector<int>).name()回归St6vectorIiSaIiEE。 有没有办法...
std::type_info::hash_code std::type_info::name std::type_info::operator!= std::type_info::operators std::unary_function std::unary_negate std::uncaught_exception std::uncaught_exceptions std::undeclare_no_pointers std::undeclare_reachable std::underflow_error std::underlying_type std::unex...
std::cout << "Object type: " << typeInfo.name() << std::endl; // 使用dynamic_cast进行安全的类型转换 Derived* derivedPtr = dynamic_cast<Derived*>(basePtr); if (derivedPtr != nullptr) { std::cout << "Dynamic cast successful" << std::endl; ...
std::type_index::operators std::type_index::type_index std::type_info std::type_info::before std::type_info::hash_code std::type_info::name std::type_info::operator!= std::type_info::operators std::unary_function std::unary_negate std::uncaught_exception std::uncaught_exceptions std...
const char* TypeInfo::name() const{ assert(pInfo_); return pInfo_->name(); }// Comparison operators inline bool operator==(const TypeInfo& lhs, const TypeInfo& rhs) { return (lhs.Get() == rhs.Get()) != 0; } inline bool operator<(const TypeInfo& lhs, const TypeInfo&...
std::type_info::before std::type_info::hash_code std::type_info::name std::type_info::operator!= std::type_info::operators std::unary_function std::unary_negate std::uncaught_exception std::uncaught_exceptions std::undeclare_no_pointers std::undeclare_reachable std::underflow_error std:...
#include <iostream> #include <string> #include <typeinfo> #include <utility> class person { public: explicit person(std::string n) : name_(std::move(n)) {} virtual const std::string& name() const { return name_; } private: std::string name_; }; class employee : public person ...
std::type_index::hash_code std::type_index::name std::type_index::operators std::type_index::type_index std::type_info std::type_info::before std::type_info::hash_code std::type_info::name std::type_info::operator!= std::type_info::operators std::unary_function std::unary_negat...