多级派生情况下派生类的构造函数
2011-05-30 14:58
218 查看
#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
Student(int n,string nam)
{
num=n;
name=nam;
}
void display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
}
~Student(){}
protected:
int num;
string name;
};
class Student1:public Student
{
public:
Student1(int n,string nam,int a):
Student(n,nam)
{
age=a;
}
void show()
{
display();
cout<<"age:"<<age<<endl;
}
~Student1(){}
private:
int age;
};
class Student2:public Student1
{
public:
Student2(int n,string nam,int a,double s):
Student1(n,nam,a)
{
score=s;
}
void show_all()
{
show();
cout<<"score:"<<score<<endl;
}
~Student2(){}
private:
double score;
};
int main()
{
Student2 stud2(2008482271,"帅哥",24,100);
stud2.show_all();
return 0;
}
#include<string>
using namespace std;
class Student
{
public:
Student(int n,string nam)
{
num=n;
name=nam;
}
void display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
}
~Student(){}
protected:
int num;
string name;
};
class Student1:public Student
{
public:
Student1(int n,string nam,int a):
Student(n,nam)
{
age=a;
}
void show()
{
display();
cout<<"age:"<<age<<endl;
}
~Student1(){}
private:
int age;
};
class Student2:public Student1
{
public:
Student2(int n,string nam,int a,double s):
Student1(n,nam,a)
{
score=s;
}
void show_all()
{
show();
cout<<"score:"<<score<<endl;
}
~Student2(){}
private:
double score;
};
int main()
{
Student2 stud2(2008482271,"帅哥",24,100);
stud2.show_all();
return 0;
}
相关文章推荐
- 多级派生情况下派生类的构造函数
- 多级派生情况下的派生类的构造函数
- 多级派生情况下派生类的构造函数
- 【继承与派生】SDUT 2713 - 5-3 多级派生类的构造函数
- 2713 5-3 多级派生类的构造函数
- 【C++继承与派生之二】有子对象的派生类的构造函数
- 5-3 多级派生类的构造函数
- 鸡啄米:C++编程入门系列之四十二(继承与派生:虚基类及其派生类的构造函数)
- 继承与派生:虚基类及其派生类的构造函数
- 【C++继承与派生之二】有子对象的派生类的构造函数
- 5-3 多级派生类的构造函数
- 5-3 多级派生类的构造函数
- 三十九、继承与派生:派生类的构造函数****
- 【2713】 多级派生类的构造函数
- 5-3 多级派生类的构造函数
- sdut 5-3 多级派生类的构造函数
- 继承与派生3:派生类的构造函数与析构函数
- 5-3 多级派生类的构造函数
- SDUT-2713-->5-3 多级派生类的构造函数
- sdut 5-3 多级派生类的构造函数