C++ Primer 5th笔记(chap 19 特殊工具与技术)type_info 类
生活随笔
收集整理的這篇文章主要介紹了
C++ Primer 5th笔记(chap 19 特殊工具与技术)type_info 类
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. type_info 的操作
| t1 == t2 | 如果type_info對象t1和t2表示同一種類型,則返回true |
| t1 != t2 | 如果type_info對象t1和t2表示不同的類型,則返回true |
| t.name() | 返回一個C風格字符串,表示類型名字的可打印形式 |
| t1.before(t2) | 返回一個bool值,表示t1是否位于t2之前,順序關系依賴于編譯器 |
- type_info類沒有默認構造函數
- 它的拷貝和移動構造函數以及賦值運算符都被定義為刪除的。無法定義或者拷貝type_info類型的對象,也不能為type_info對象賦值。
- 創建type_info對象的唯一途徑就是使用typeid運算符。
1.1 name函數
int arr[10]; Derived d; Base* p = &d;cout << typeid(42).name() << endl; cout << typeid(arr).name() << endl; cout << typeid(std::string).name() << endl; cout << typeid(d).name() << endl; cout << typeid(p).name() << endl;輸出結果:
int int [10] class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > class Derived class Base *總結
以上是生活随笔為你收集整理的C++ Primer 5th笔记(chap 19 特殊工具与技术)type_info 类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++ Primer 5th笔记(cha
- 下一篇: C++ Primer 5th笔记(cha