首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

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

2012-11-23 
关于c++中类的继承与派生#includeiostreamusing namespace stdclass A{public:int xA(int a,int b){a

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

#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呢

热点排行