day6

1.继承
class student //子类
{
public:
student(int id, string name)
{
this->id = id;
this->name = name;
}
void print()//打印子类中的内容
{
cout << id << endl;
cout << name << endl;
}
private:
int id;
string name;
};
class student3:public student //student3包括student中的数据
{
public:
student3(int id, int score, string name) :student(id,name)
{
this->score = score;
}
void print()
{
student::print();
cout << score << endl;
}
private:
int score;
};
需要通过被继承类中的构造函数来对被继承类中的变量进行赋值。
2.
public继承:
public中的数据在继承后的类中类外都能直接引用
protected中的数据只能在继承后的类中被直接引用
private中的数据不能通过被继承的类引用

protected继承:
原父类中的public->private private->private protected->protected

private继承:
所有的类型都变成private
3.多继承
class student:public a,public b
{};
当继承出现下面这种情况时,用虚继承,防止继承后出现两个材质m
class sofa:virtual public jiaju
{};
class bed:virtua public jiaju
{};

.day6