⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typeid_2.cpp

📁 不错书对C++/C程序员很有用的大家不要错过.
💻 CPP
字号:
#include <iostream.h>
#include <typeinfo.h>

class Base {
   int a, b;
   virtual void func(void) {};
 };

class Derived1: public Base {
   int i, j;
 }

class Derived2: public Base {
   int k;
 }

void main(void)
 {
   int i;
   Base *p, baseobj;
   Derived1 obj1;
   Derived2 obj2;

   cout << "Typeid of i is: ";
   cout << typeid(i).name() << endl;
   p = &baseobj;
   cout << "p is currently pointing to an object of type: ";
   cout << typeid(*p).name() << endl;
   p = & obj1;
   cout << "p is now pointing to an object of type: ";
   cout << typeid(*p).name() << endl;
   p = & obj2;
   cout << "p is finally pointing to an object of type: ";
   cout << typeid(*p).name() << endl;
 }
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -