Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4191780
  • 博文数量: 776
  • 博客积分: 13014
  • 博客等级: 上将
  • 技术积分: 10391
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-22 17:00
文章分类

全部博文(776)

文章存档

2015年(55)

2014年(43)

2013年(147)

2012年(20)

2011年(82)

2010年(429)

分类: C/C++

2010-07-16 08:31:01

给个定义的形式和例子:
定义形式:
    派生类构造函数名(总参数列表):基类1构造函数(参数列表),基类2构造函数(参数列表),....基类n构造函数(参数列表)
{  派生类中新增成员初始化语句}
  例子:
  class teacher         //基类1
{
public:
teacher(string nam,int a,string t)   //构造函数
{
  name=nam;
  age=a;
  title=t;
}
void display()
{
  cout<<"name:"<  cout<<"age:"<  cout<<"title:"< }
protected:
string name;
int age;
string title;
};
class student         //基类2
{
public:
student(char nam[],char s,float sco)   //基类2的构造函数
{
  strcpy(name1,nam);
  sex=s;
  score=sco;
}
void display1()
{
  cout<<"name:"<  cout<<"sex:"<  cout<<"score:"< }
protected:
string name1;
char sex;
float score;
};
class graduate:public teacher,public student  //以公有的方式分别从teacher 和student继承
{
public:
graduate(string nam,int a,char s,string t,float sco,float w):
   teacher(nam,a,t),student(nam,s,sco),wage(w)
   {
   }
   void show()
   {
    cout<<"name:"<    cout<<"age:"<    cout<<"sex:"<    cout<<"score:"<    cout<<"title:"<    cout<<"wage:"<   }
private:
float wage;
};
阅读(1137) | 评论(0) | 转发(0) |
0

上一篇:CByteArray

下一篇:edit 控件数组

给主人留下些什么吧!~~