亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

typeid(m_a).name(),這里為什么要加上name()

typeid(m_a).name(),這里為什么要加上name()

C
開心每一天1111 2022-07-22 16:15:16
程序是這樣的:Comparetor(T a,T b):m_a(a),m_b(b){}int compare(void){cout<<typeid(m_a).name()<<endl;//這句話不明白}
查看完整描述

2 回答

?
蕪湖不蕪

TA貢獻1796條經驗 獲得超7個贊

cout<<typeid(m_a).name()<<endl;//
typeid 是c++語言開啟了RTTI (運行時類型信息)的功能,
這個功能開啟c++會在每個類型上給個typeid 的類,name()是這個類的成員函數

查看完整回答
反對 回復 2022-07-24
?
尚方寶劍之說

TA貢獻1788條經驗 獲得超4個贊

typeid 是運算符,檢查 表達式的 類型:
typeid (表達式)
計算返回 type_info 型的 常對象地址,頭文件 <typeinfo>里定義。.name() 返回類型名字。

書上例子:

#include <iostream>
#include <typeinfo>
usingnamespace std;

int main () {
int * a,b;
a=0; b=0;
if (typeid(a) != typeid(b))
{
cout << "a and b are of different types:\n";
cout << "a is: " << typeid(a).name() << '\n';
cout << "b is: " << typeid(b).name() << '\n';
}
return 0;
}
輸出:
a and b are of different types:
a is: int *
b is: int

如果是 class , 它能返回 class 名字。


查看完整回答
反對 回復 2022-07-24
  • 2 回答
  • 0 關注
  • 178 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號