设为首页收藏本站

新微赢技术网

 找回密码
 注册
搜索
热搜: 回贴
查看: 1622|回复: 2
打印 上一主题 下一主题

多继承问题

[复制链接]
跳转到指定楼层
1#
发表于 2009-11-4 02:25:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
工程由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();
}
2#
发表于 2009-11-4 02:25:29 | 只看该作者
说一下是什么警告?
回复 支持 反对

使用道具 举报

3#
发表于 2009-11-4 02:25:30 | 只看该作者
fatal error C1083: Cannot open include file: 'School_Source.h': No such file or directory
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

申请友链|小黑屋|最新主题|手机版|新微赢技术网 ( 苏ICP备08020429号 )  

GMT+8, 2024-11-19 07:48 , Processed in 0.099837 second(s), 8 queries , Gzip On, Memcache On.

Powered by xuexi

© 2001-2013 HaiAn.Com.Cn Inc. 寰耽

快速回复 返回顶部 返回列表