如何在C 中检查确切的类型信息(具有CV-REF-POIRT特征)
How to check the exact type info (with cv-ref-pointer traits) in C++?
#include <iostream>
using namespace std;
int main()
{
cout << typeid(int).name() << endl;
cout << typeid(int&).name() << endl;
cout << typeid(int&&).name() << endl;
cout << typeid(const int).name() << endl;
cout << typeid(const int&).name() << endl;
cout << typeid(const int&&).name() << endl;
}
我认为输出应该是:
int
int&
int&&
const int
const int&
const int&&
但是,实际输出是:
int
int
int
int
int
int
Clang&amp;VC 以相同的方式做。
是否有可靠的方法来检查C ?
请注意,当您将参考类型传递给TypeID操作员时,结果std::type_info
对象表示引用类型。
1(指的是代表类型
type
的std::type_info
对象。如果type
是参考类型,则结果是指代表引用类型的std::type_info
对象在所有情况下,CV-Qualifier都被TypeID忽略(即
typeid(const T) == typeid(T)
(
并注意std::type_info::name
返回的是实现定义。
您可以从有效的现代C (Scott Meyers(项目4:知道如何查看推论类型,以在编译时获取类型名称。例如
template <typename>
struct TD;
然后将其用作
TD<int> td;
您会收到一些提及类型名称的消息,例如
error: implicit instantiation of undefined template 'TD<int>'
live(clang(
相关文章:
- Keil armcc 生成类型信息名称,即使使用 --no_rtti_data
- 使用 trie 数据结构链接不同类型的信息
- 错误:未定义对"静脉类型信息::电池访问"的引用
- 只知道运行时的数据类型.如何将数据详细信息隐藏到使用它们的其他类
- 自动初始值设定项类型ID 信息
- 元数据操作失败LNK2022错误 (8013118D):重复类型中的布局信息不一致 (选择设备参数):(0x020002
- 针对特殊情况,使用其他状态信息扩展基元类型
- 如何从模板获取类型和值信息
- 将不同的模板化类存储在一个容器中,而不会丢失有关其类型的信息
- 如何在编译过程中输出C 类型信息
- 如何在C 中检查确切的类型信息(具有CV-REF-POIRT特征)
- 为什么类型转换对象不会更改其地址?有关对象类型的信息存储在哪里?
- 共享库中非模板基的模板子类导致未定义的符号类型信息'class'链接错误
- 为什么C++不使用集中存储类型信息以实现高效的 RTTI
- 仅使用有关类型而不是对象的信息返回调用的类型
- 给定DDS主题名称,可以在运行时确定主题类型信息
- 使用友元函数从多态类中检索类型信息
- 如何在函数模板中隐式推导数组中元素的类型信息
- 使用标准类型的动态类型信息实例化标识符
- 如何在 c++ 中获取有关服务的启动类型的信息