Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嘿,我来自 java 背景,我正在阅读一本 c++ 书,它说 typeid() 返回 type_info 的对象。但是,如果我尝试做类似的事情;
type_info *x = typeid(somthing);
我收到错误:不存在从 const type_info 到 type_info 的合适转换。
有人能告诉我如何获得对 type_info 对象的引用吗?
运算符typeid返回一个 . const type_info&因此,您需要一个 const 引用,而不是指针:
typeid
const type_info&
const std::type_info &x = typeid(something);