C++多重继承
//fds.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#include<iostream>#include<string>usingna...
// fds.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
class Teacher //定义教师任课类
{
public:
Teacher(string); //进行初始化
protected:
string title; //职称
};
Teacher::Teacher( string t)
{
title=t;
}
class Leader //定义职务级别类
{
public:
Leader( string p); //初始化
protected:
string postion; //职位
};
Leader::Leader( string p)
{
postion=p;
}
class Teacher_Leader: public Leader, public Teacher //多重继承
{
public:
Teacher_Leader(string t,string p,string w):Teacher(t),Leader(p),wage(w){}; ???????????
void Show();
protected:
string wage; //工资
};
void Teacher_Leader::Show() //定义成员函数
{
cout<<"职务是:"<<title<<endl;
cout<<"职位是:"<<postion<<endl;
cout<<"工资是:"<<wage<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
Teacher_Leader person("语文","教员","3500"); //初始化类对象
person.Show();
return 0;
}
我得疑问那一行已经打上了问号。。请问Teacher_Leader(string t,string p,string w):Teacher(t),Leader(p),wage(w){};是什么意思呢?最后为什么还有个{}呢? 展开
//
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
class Teacher //定义教师任课类
{
public:
Teacher(string); //进行初始化
protected:
string title; //职称
};
Teacher::Teacher( string t)
{
title=t;
}
class Leader //定义职务级别类
{
public:
Leader( string p); //初始化
protected:
string postion; //职位
};
Leader::Leader( string p)
{
postion=p;
}
class Teacher_Leader: public Leader, public Teacher //多重继承
{
public:
Teacher_Leader(string t,string p,string w):Teacher(t),Leader(p),wage(w){}; ???????????
void Show();
protected:
string wage; //工资
};
void Teacher_Leader::Show() //定义成员函数
{
cout<<"职务是:"<<title<<endl;
cout<<"职位是:"<<postion<<endl;
cout<<"工资是:"<<wage<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
Teacher_Leader person("语文","教员","3500"); //初始化类对象
person.Show();
return 0;
}
我得疑问那一行已经打上了问号。。请问Teacher_Leader(string t,string p,string w):Teacher(t),Leader(p),wage(w){};是什么意思呢?最后为什么还有个{}呢? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询