张凌枫<2016.12.18>【连续第31天总结】
A.今日任务
1.多继承和多重继承代码练习
2.多学习了一个
B.具体任务
1.多继承的顺序是按照输入顺序来的
2.多继承继承的时候最好是写上继承方式
3.多重继承顺序为长者类-》父类-》子类依次运行
4.这种写法比一个一个的定义方便得不知道高到哪里去了
5.继承的后面不能加分号啊!!!!!!!!!!!!!!!!!!
6.写的时候不能忘了分号啊!!!!!!!!!!!!!!!!!!
附代码:
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
class Worker//工人类
{
public:
Worker(string name)
{
m_strName = name;
cout << "Worker" << endl;
}
~Worker()
{
cout << "~Worker" << endl;
}
void work()
{
cout << m_strName << endl;
cout << "work" << endl;
}
protected:
string m_strName;
};
class Children//小屁孩类
{
public:
Children(int age)
{
m_iAge = age;
cout << "Children" << endl;
}
~Children()
{
cout << "~Children" << endl;
}
void play()
{
cout << m_iAge << endl;
cout << "play" << endl;
}
protected:
int m_iAge;
};
class ChildLabourer :public Worker,public Children//一个童工类(继承工人和小屁孩类)
{
public:
ChildLabourer(string name, int age):Worker(name),Children(age)
{
cout << "ChildLabourer" << endl;
}
~ChildLabourer()
{
cout << "~ChildLabourer" << endl;
}
};
int main(void)
{
ChildLabourer *p = new ChildLabourer("长者",+1s);
p->work();
p->play();
delete p;
p = NULL;
return 0;
}
明日任务
虚继承
多复习一个