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

当基础看了

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

CFirst

CSecond 2

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

A

请按任意键继续. . .