[問題] RTTI typeid 的用法
以下是我照著書上範例打的,還有output結果
使用Dev-c++編譯~
#include<iostream>
#include<typeinfo>
using namespace std;
class BaseClass{
virtual void f() {};
//...
};
class Derived1 : public BaseClass{
};
class Derived2 : public BaseClass{
};
int main()
{
double j;
BaseClass *p, baseob;
Derived1 ob1;
Derived2 ob2;
cout << "Typeid of j is: ";
cout << typeid(j).name() << endl;
p = &baseob;
cout << "p is pointing to an object of type: ";
cout << typeid(*p).name() << endl;
p = &ob1;
cout << "p is pointing to an object of type: ";
cout << typeid(*p).name() << endl;
p = &ob2;
cout << "p is pointing to an object of type: ";
cout << typeid(*p).name() << endl;
system("pause");
return 0;
}
結果:
Typeid of j is: d
p is pointing to an object of type: 9BaseClass
p is pointing to an object of type: 8Derived1
p is pointing to an object of type: 8Derived2
問題:
請問為什麼output那邊三個type name之前會各有一個數字呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.245.211
推
02/15 16:48, , 1F
02/15 16:48, 1F
→
02/15 16:48, , 2F
02/15 16:48, 2F
推
02/15 17:54, , 3F
02/15 17:54, 3F
→
02/15 17:56, , 4F
02/15 17:56, 4F
推
02/15 18:42, , 5F
02/15 18:42, 5F
→
02/15 18:43, , 6F
02/15 18:43, 6F
→
02/15 18:44, , 7F
02/15 18:44, 7F
推
02/16 00:44, , 8F
02/16 00:44, 8F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章