编辑:似乎错误发生在我的std :: ostream& write(std :: ostream& ostr)声明以及我的int mdays(int mon)const声明中。当我评论这两个函数时,#endif警卫不再出现错误,但我不确定为什么这两个声明会有任何问题。
我已经为我正在编写的程序编写了一个头文件,但根据我的代码编辑器,#endif标题以红色突出显示,这意味着它无法关闭。我已多次查看我的声明,似乎一切都已到位,所以我很困惑为什么我会收到此错误。这是我的代码:
#include <iostream>
#ifndef SICT_DATE_H__
#define SICT_DATE_H__
//readErrorCode_ definitions
#define NO_ERROR 0 //no error date if valid
#define CIN_FAILED 1 //istream failed when entering information
#define YEAR_ERROR 2 //year value is invalid
#define MON_ERROR 3 //month value is invalid
#define DAY_ERROR 4 //day value is invalid
namespace sict {
class Date {
int year_; //holds year; a four digit int between MIN_YEAR and MAX_YEAR
int mon_; //month of the year, between 1 to 12
int day_; //day of the month, not that a leap year in February is 29 days, (see mday())
int readErrorCode_; //holds an error code with which the caller program can reference
//to find out if the date value is valid and if not, which part is erroneous.
int value() const; //function already implemented
void errCode(int errorCode); //sets the readErrorCode_ member variable to one of
//the values mentioned above
void isValid(); //determine is date values are within range
//Constructors
public:
Date(); //default constructor: sets year_, mon_ and day_ to "0" and readErrorCode_ to NO_ERROR
Date(int year, int month, int day); //three argument constructor: accepts three arguments to set values
//of year_, mon_ and day_ attributes. Also sets readErrorCode_ to NO_ERROR
//comparison logical operator overloads
bool operator==(const Date& D)const;
bool operator!=(const Date& D)const;
bool operator<(const Date& D)const;
bool operator>(const Date& D)const;
bool operator<=(const Date& D)const;
bool operator>=(const Date& D)const;
int mdays(int mon)const; //function is already implemented and provided
//accessor or getter member functions
int errCode()const; //returns readErrorCode_ value
bool bad()const; //returns true if readErrorCode_ is not equal to zero
//IO member functions
std::istream& read(std::istream& istr);//reads date in the following format: YYY?MM?DD
std::ostream& write(std::ostream& ostr)const;
};
//writes the date using ostr argument in the following format
//YYY/MM/DD then return the ostr
std::ostream& operator<<(std::ostream& os, const Date& D);
std::istream& operator>>(std::istream& is, Date& D);
}
#endif