一直在赶场,下面是出了N次的题... 

当基础看了

  1. #include <iostream> 
  2. using namespace std; 
  3.  
  4. namespace Torxie 
  5. { 
  6.     //  
  7.     class CFirst 
  8.     { 
  9.         public: 
  10.             void func() 
  11.             { 
  12.                 cout<< "CFirst"<<endl; 
  13.                 func2(); 
  14.             } 
  15.             virtual void func2() 
  16.             { 
  17.                 cout<<"CFirst 2"<<endl;  
  18.             } 
  19.     }; 
  20.      
  21.     class CSecond : public CFirst 
  22.     { 
  23.         public: 
  24.             void func() 
  25.             { 
  26.                 cout<<"CSecond"<<endl; 
  27.             } 
  28.             virtual void func2() 
  29.             { 
  30.                 cout<<"CSecond 2"<<endl; 
  31.             } 
  32.     }; 
  33.      
  34.     class CA 
  35.     { 
  36.         public: 
  37.             void func();     
  38.         private: 
  39.             int m;       
  40.     }; 
  41.     void CA::func() 
  42.     { 
  43.         cout<<"A"<<endl;     
  44.     } 
  45.      
  46.     class CB 
  47.     { 
  48.         public: 
  49.         void func();     
  50.         private: 
  51.         int m; 
  52.     }; 
  53.     void CB::func() 
  54.     { 
  55.         cout<<"B"<<endl;     
  56.     } 
  57. } 
  58.  
  59. int main(int argc, char *argv[]) 
  60. { 
  61.     using namespace Torxie;  
  62.     CFirst *pFirst = new CSecond; 
  63.     pFirst->func();  //
  64.     cout<<"-------------------------"<<endl; 
  65.     CA *pCA = (CA*)new CB(); // reinterpre_cast<A*> 
  66.     pCA->func(); 
  67.     return 0; 
  68. } 

CFirst

CSecond 2

-------------------------

A

请按任意键继续. . .