关于c++中类的继承与派生

来源:岁月联盟 编辑:猪蛋儿 时间:2012-11-13

c++class
[cpp] 
#include<iostream> 
using namespace std; 
class A{ 
public:   
      int x; 
      A(int a,int b){ 
          a=x; 
          b=u;} 
      void prt(){ 
      cout<<cout<<x<<endl;} 
private: 
    int u; 
}; 
class B:public A{ 
public: 
    B(int a,int b,int c): 
      A(a,b){ 
          y=c;} 
      int y; 
      void prt(){ 
          cout<<"A::x=:"<<A::x<<endl; 
          A::prt(); 
          cout<<" B::y=:"<<B::y<<endl; 
      } 
 }; 
int main(){ 
    B b(1,2,3); 
    b.prt(); 
    cout<<b.x<<endl; 

 
         

为什么x的值不是1呢

下一篇:UVA 11991