C++嵌套類示例

#include<iostream>
  using namespace std;
  class zoo
  {
   const static int age=9999;
   static int res;
  public:
   zoo()
   {
   cout<<"this is zoo!" << endl;
   }
   class animal
   {
   public:
   animal()
   {
   cout << "z.age=" << age << endl;
   cout << "z.res=" << res << endl;
   cout << "this is animal" << endl;
   }
   void ShowTypeInfo()
   {
   cout << typeid(*this).name() << endl;
   }
   };
   class person
   {
   public:
   person()
   {
   cout << "this is person!" << endl;
   }
   void ShowTypeInfo()
   {
   cout << typeid(*this).name() << endl;
   }
   class hand
   {
   public:
   hand()
   {
   cout << "this is hand!" << endl;
   }
   void ShowTypeInfo()
   {
   cout << typeid(*this).name() << endl;
   }
   };
   };
   void ShowTypeInfo()
   {
   cout << typeid(*this).name() << endl;
   }
  };
  int zoo::res =100000;
  int main()
  {
   zoo xazoo;
   xazoo.ShowTypeInfo ();
   zoo::person ps;
   ps.ShowTypeInfo ();
   zoo::animal an;
   an.ShowTypeInfo ();
   zoo::person::hand chenbincheng;
   chenbincheng.ShowTypeInfo ();
   return 0;
  }  
發佈了71 篇原創文章 · 獲贊 0 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章