| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 417 人关注过本帖
标题:多继承问题
只看楼主 加入收藏
lixang
Rank: 1
等 级:新手上路
帖 子:231
专家分:0
注 册:2006-7-15
收藏
 问题点数:0 回复次数:2 
多继承问题

工程由School_Source.h ,School_Source.cpp,Main.cpp构成

请大家在自己的机子上运行以下:

此程序有4个警告;我不能解决,希望大家帮助!

//School_Source.h

class DateSou

{

private:

char* P_name; char* P_city;

char* P_state; char* P_zip;

public:

DateSou();

DateSou(char *name,char* city,char*state,char*zip);

~DateSou();

virtual void print();

protected:

char* strSave(char*s);

};

//////////////////////////////////////////////////////////////////////////////////

class Stu:virtual public DateSou

{

private:

char* P__major;

int __idName;

int __level;

public:

Stu(char*name,char*city,char*state,char*zip,char*major,int idName,int level)

:DateSou(name,city,state,zip)

{ P__major=strSave(major); __idName=idName; __level=level; }

Stu(char*major,int idName,int level)

{ P__major=strSave(major); __idName=idName; __level=level; }

~Stu()

{ delete [] P__major;}

virtual void print();

protected:

void disp();

};

////////////////////////////////////////////////////////////////////////////////////

class Staff:virtual public DateSou

{

private:

char* P__dept;

float __hourlyWage;

public:

Staff(char*name,char*city,char*state,char*zip,char*dept,float hourlyWage)

:DateSou(name,city,state,zip)

{ P__dept=strSave(dept); __hourlyWage=hourlyWage;}

Staff(char*dept,float hourlyWage)

{ P__dept=strSave(dept); __hourlyWage=hourlyWage;}

~Staff()

{ delete []P__dept;}

virtual void print();

protected:

void disp();

};

///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

class StuStaff :public Stu ,public Staff

{

public:

StuStaff(char*name,char*city,char*state,char*zip,char*major,

int idName,int level, char*dept,float hourlyWage)

:DateSou(name,city,state,zip),

Stu(major,idName,level), Staff(dept,hourlyWage)

{}

virtual void print();

};

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//School_Source.cpp

#include"School_Source.h"

#include<iostream>

#include<string>

using namespace std;

/////////////////////////////////////////////////////////////////////////////////

DateSou::DateSou()

{

P_name=NULL; P_city=NULL;

P_state=NULL; P_zip=NULL;

}

DateSou::DateSou(char *name, char *city, char *state, char *zip)

{

P_name=strSave(name); P_city=strSave(city);

P_state=strSave(state); P_zip=strSave(zip);

}

DateSou::~DateSou()

{

delete P_name; delete P_city;

delete P_state; delete P_zip;

}

void DateSou::print()

{

cout<<endl<<endl<<P_name<<endl<< P_city<<", ";

cout<<P_state<<" "<<P_zip;

}

char* DateSou::strSave(char*s)

{

char*P; P=new char[strlen(s)+1];

strcpy(P,s);

return P;

}

/////////////////////////////////////////////////////////////////

void Stu::print()

{

DateSou::print();

disp();

}

void Stu::disp()

{

cout<<endl;

cout<<"\major:"<<P__major<<" ";

cout<<"\idName:"<<__idName<<" ";

cout<<"\level:"<<__level;

}

////////////////////////////////////////////////////////////////////////////

void Staff::print()

{

DateSou::print();

disp();

}

void Staff::disp()

{

cout<<"\nDepartment:"<<P__dept;

cout<<"\nhourlyWage:"<<__hourlyWage;

}

///////////////////////////////////////////////////////////////////////////////

void StuStaff::print()

{

DateSou::print();

Stu::disp();

Staff::disp();

cout<<endl;

}

//Main.cpp

#include"School_Source.h"

//using namespace std;

void main()

{

Stu OStu("张三", "北京", "Stu", "1860", "大学语文",17951,4);

Staff OStaff("李四", "上海", "Staff", "10011", "机器人自动化",3.14f);

StuStaff OStuStaff("王五", "西安", "StuStaff", "12315","历史",11111,3,

"现代哲学",6.30f);

OStu.print();

OStaff.print();

OStuStaff.print();

}

搜索更多相关主题的帖子: 继承 
2007-03-08 22:17
半支烟
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2007-1-16
收藏
得分:0 

说一下是什么警告?


2007-03-09 11:18
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
fatal error C1083: Cannot open include file: 'School_Source.h': No such file or directory

Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2007-03-09 13:08
快速回复:多继承问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021602 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved