これは私のCalendar.cppファイルです。'Date': 'クラス'型の再定義:ERROR(calendar.cppファイルのエラー)
#include <iostream>
#include <string>
#include <sstream>
#include "Calendar.h"
char months[12][10] = { "January", "February", "March","April","May","June","July","August","September","October","November","December" };
問題がクラス宣言に表示されています。
class Date {
。
private:
int dd, mm, yy;
public:
Date() {
dd = 1; mm = 1; yy = 1900;
}
Date(int m, int d, int y) {
dd = d; mm = m; yy = y;
bool check = checkdate();
if (!check) {
cout << "Invalid date give. Resetting to default" << endl;
dd = mm = 1; yy = 1900;
}
}
bool checkdate() {
bool leap = checkleapyear();
if (mm>12 || mm <= 0) //check months
return false;
if ((mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) && dd>31)
return false;
else if (leap && mm == 2 && dd>29)
return false;
else if (mm == 2 && dd>28)
return false;
else if (dd>30)
return false;
return true;
}
bool checkleapyear() {
if ((yy % 400 == 0) || (yy % 4 == 0 && yy % 100 != 0))
return true;
else
return false;
}
string toString() {
stringstream ss;
ss << months[mm - 1] << " " << dd << "," << yy;
return ss.str();
}
Date nextDate() {
int y, d, m;
if (mm == 2) {
bool flag = checkleapyear();
if (flag) {
if (dd >= 29) {
d = 1;
m = 3;
}
else
d++;
}
else {
if (dd >= 28) { d = 1; m = 3; }
else
d++;
}
y = yy;
return Date(m, d, y);
}
if ((mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10) && dd>31)
{
m++;
d = 1;
y = yy;
}
else if (mm == 12) { m = 1; y = yy++; d = 1; }
else if (dd>30) {
m++;
d = 1;
y = yy;
}
else {
d = dd + 1;
m = mm;
y = yy;
}
return Date(m, d, y);
}
void compareDates(Date &d)
{
if (d.yy>this->yy)
cout << "The first date comes before the second date" << endl;
else if (d.yy<this->yy)
cout << "The second date comes before the first date" << endl;
else if (d.yy == this->yy) {
if (d.mm>this->mm)
cout << "The first date comes before the second date" << endl;
else if (d.mm<this->mm)
cout << "The second date comes before the first date" << endl;
else {
if (d.dd>this->dd)
cout << "The first date comes before the second date" << endl;
else if (d.dd<this->dd)
cout << "The second date comes before the first date" << endl;
else {
cout << "The two dates are equal" << endl;
}
}
}
}
};
これは私のCalendar.hファイルです。
#ifndef CALENDAR_H
#define CALENDAR_H
#include <iostream>
#include <string>
using namespace std;
class Date {
private:
int dd, mm, yy;
public:
Date();
Date(int m, int d, int y);
bool checkdate();
bool checkleapyear();
string toString();
Date nextDate();
void compareDates(Date &d);
};
#endif
「 'Date': 'class' type redefinition」というCalendar.cppファイルにエラーが発生します。クラス内のいくつかの要素を変更して動作させようとしましたが、他にも問題があるようです。
?クラスとその実装はどのように使用しているC++ブックに記述されていますか?コンパイラは、文字通り問題が何であるかを伝えています。 – PaulMcKenzie