日、月、年の変数と、それを使用する一連の演算子関数を保持する「日付」クラスを C++ で作成しています。
クラスに date.h ヘッダーと date.cpp があり、date.cpp の演算子関数の 1 つが大量のエラーを出しています。
date.cpp (この演算子関数で、追加された日数をカウントし、新しい日付オブジェクトを返し、元の日付オブジェクトへの変更を回避する必要があります。)
date date::operator+(long days) const{
date dTemp( date.getDay(), date.getMonth(), date.getYear() );
for(int i=0;i<days;i++){
//If days go over a months day count.
if(dTemp.getDay() >= daysInMonth[dTemp.getMonth()]){
dTemp.setDay(1);
if(dTemp.getMonth() < 12){
dTemp.setMonth(dTemp.getMonth() + 1);
}
else{
//Changing a year.
dTemp.setMonth(1);
dTemp.setYear(dTemp.getYear() + 1);
}
}
else{
dTemp.setDay(dTemp.getDay() + 1);
}
}
return dTemp;
}
エラー:
1>h:\c++\teht21\teht20\date.cpp(74): error C2143: syntax error : missing ')' before '.'
1>h:\c++\teht21\teht20\date.cpp(74): error C3484: syntax error: expected '->' before the return type
1>h:\c++\teht21\teht20\date.cpp(74): error C2061: syntax error : identifier 'getDay'
1>h:\c++\teht21\teht20\date.cpp(79): error C2065: 'dTemp' : undeclared identifier
1>h:\c++\teht21\teht20\date.cpp(79): error C2228: left of '.getDay' must have class/struct/union
1> type is ''unknown-type''
74 行目は次のとおりです。
date dTemp( date.getDay(), date.getMonth(), date.getYear() );
どんな助けでも大歓迎です。さらにコードが必要な場合は、お知らせください。