为什么会出现错误?
在extDateType.h:2:0包含的文件中, 从calendarType.h:3:dateType.h:1:7:错误:重新定义“ class dateType”类dateType
我不明白自己在代码中定义的内容。一切似乎都受到控制。请解释。
dateType.h
class dateType
{
public:
dateType (int month=1, int day=1, int year=0001);
void setDate(int month, int day, int year);
void setMonth(int);
void setDay(int);
void setYear(int);
void print() const;
int numberOfDaysLeft();
int numberOfDaysPassed();
void ADD_TO_DATE(int nDays);
int get_Month() const;
int get_day() const;
int get_Year() const;
int get_num_days_month();
bool Leap_Year();
private:
int z_Month;
int z_Day;
int z_Year;
};
dateTypeImp.cpp
#include <iostream>
#include <string>
#include "dayType.h"
using namespace std;
string dayType::weekDays[7] = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday",
"Saturday"};
void dayType::print() const
{
cout << weekDay;
}
string dayType::nextDay() const
{
int i;
for (i = 0; i < 7; i++)
if (weekDays[i] == weekDay)
break;
return weekDays[(i + 1) % 7];
}
string dayType::prevDay() const
{
if (weekDay == "Sunday")
return "Saturday";
else
{
int i;
for (i = 0; i < 7; i++)
if (weekDays[i] == weekDay)
break;
return weekDays[i - 1];
}
}
void dayType::addDay(int nDays)
{
int i;
for (i = 0; i < 7; i++)
if (weekDays[i] == weekDay)
break;
weekDay = weekDays[(i + nDays) % 7];
}
void dayType::setDay(string d)
{
weekDay = d;
}
string dayType::get_day() const
{
return weekDay;
}
dayType::dayType()
{
weekDay = "Sunday";
}
dayType::dayType(string d)
{
weekDay = d;
}
extDateType.h
#include <string>
#include "dateType.h"
using namespace std;
class extDateType: public dateType
{
public:
static string Name_Month[12];
void printLongDate();
void setDate(int, int, int);
void setMonth(int m);
void printLongMonthYear();
extDateType();
extDateType(int, int, int);
private:
string dName_Month;
};
calendarType.h
#include "dateType.h"
#include "extDateType.h"
#include "dayType.h"
// declare the class of calendar Type
class calendarType
{
// declare the public set month, set year with their ints m and y
public:
void setMonth(int m);
void setYear(int y);
// the get function of the set
int get_Month();
int get_Year();
// the void without a return value currently for printing the calender
void printCalendar();
// name calenderType with assigned ints from the month and year
calendarType();
calendarType(int m, int y);
/* name the private variables. This assignment was an expansion of the created
calenderType, dateType, and extDateType declared in the earlier prog
execises in chapter 11. The variables will be named closely due to it
being an expansion from prior problem solutions. */
private:
// name the first day of daytype
dayType firstDayOfMonth();
//no return currently for the printing of titles and dates
void printTitle();
void printDates();
//other private named in the class
extDateType firstDate;
dayType firstDay;
};