多个头文件怎样确定包含关系

qazwsx123asdfadf qazwsx123asdfadf 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
Date.h
class Date
{
public:
Date(int year=0,int month=0,int day=0);
~Date(){cout<<"destructing Date"<<endl;}
void PrintDate();
int year;
int month;
int day;
};
CPerson.h
class CPerson
{
public:
CPerson(){}
CPerson(Date birthday,int Num,string sName="张三");
CPerson(int year,int month,int day,int Num,string sName="张三");
string GetName();
int GetNum();
Date GetBirthday();
friend bool Compare(CPerson &p1, CPerson &p2);
private:
Date birthday;
const string sName;
int Num;
};
CStudent.h
class CStudent:virtual private CPerson
{
public:
CStudent(){}
CStudent(CPerson person, int StuNum);
CStudent(Date birthday,int Num,int StuNum,string sName="张三");
CStudent(int year,int month,int day,int Num,int StuNum,string sName="张三");
string GetName();
Date GetBirthday();
int GetNum();
int GetStuNum();
private:
int StuNum;
};
CTeacher.h
class CTeacher:virtual public CPerson
{
public:
CTeacher(){}
CTeacher(CPerson person, Date time);
CTeacher(Date birthday,int Num,Date time,string sName="张三");
CTeacher(int year,int month,int day,int Num,Date time,string sName="张三");
Date GetTime() ;
private:
Date time;
};
CTA.h
class CTA:public CStudent,public CTeacher
{
public:
CTA(int year,int month,int day,int Num,int StuNum,Date time,int No,string sName="张三");
int GetNo();
private:
int No;
};
main.cpp
#include "CTA.h"
void main()
{
CPerson a(1,2,3,4,"asd");
}
错误为Compiling...
main.cpp
Linking...
CStudent.obj : error LNK2005: "public: __thiscall Date::Date(int,int,int)" (??0Date@@QAE@HHH@Z) already defined in CPerson.obj
CStudent.obj : error LNK2005: "public: void __thiscall Date::PrintDate(void)" (?PrintDate@Date@@QAEXXZ) already defined in CPerson.obj
CTA.OBJ : error LNK2005: "public: __thiscall Date::Date(int,int,int)" (??0Date@@QAE@HHH@Z) already defined in CPerson.obj
CTA.OBJ : error LNK2005: "public: void __thiscall Date::PrintDate(void)" (?PrintDate@Date@@QAEXXZ) already defined in CPerson.obj
CTeacher.obj : error LNK2005: "public: __thiscall Date::Date(int,int,int)" (??0Date@@QAE@HHH@Z) already defined in CPerson.obj
CTeacher.obj : error LNK2005: "public: void __thiscall Date::PrintDate(void)" (?PrintDate@Date@@QAEXXZ) already defined in CPerson.obj
main.obj : error LNK2005: "public: __thiscall Date::Date(int,int,int)" (??0Date@@QAE@HHH@Z) already defined in CPerson.obj
main.obj : error LNK2005: "public: void __thiscall Date::PrintDate(void)" (?PrintDate@Date@@QAEXXZ) already defined in CPerson.obj
Debug/CPerson.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

CPerson.exe - 9 error(s), 0 warning(s)
这是什么错误,这几个头文件应该怎样确定包含关系啊!(与他们相对应的cpp文件,我包含的相应的头文件)
谢谢大家了!!!
...全文
评论 3
收藏 已收藏
分享
返回顶部
qazwsx123asdfadf
新手乐园 33,314 成员 41,769 内容