little_greg Posted May 26, 2010 Report Share Posted May 26, 2010 Объявление класса: #ifndef DATE_H_#define DATE_H_#include <iostream>namespace DATE{class Date{ private: int d, m, y; //error: 'int DATE::Date::d', 'int DATE::Date::m', 'int DATE::Date::y' is private static Date default_date; public: struct Bad_Date { Bad_Date() {} }; enum Month {jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec}; Date(int dd = 1, Month mm = Month(1), int yy = 1970); int day() const; Month month() const; int year() const; int leapyear(int yy); static void set_default(int, Month, int); Date& add_day(int n); Date& add_month(int n); Date& add_year(int n); bool check_date(const Date& dat); bool operator==(const Date& dat); bool operator!=(const Date& dat); bool operator<(const Date& dat); bool operator>(const Date& dat); Date operator++(); Date operator--(); Date operator+=(int n); Date operator-=(int n); Date operator+(int n); Date operator-(int n); friend std::ostream& operator<<(std::ostream& os, const Date& dat); friend std::istream& operator>>(std::istream& is, Date& dat);};};#endif Определение функций: std::ostream& operator<<(std::ostream& os, const Date& dat){os << dat.d << "/" << dat.m << "/" << dat.y << "\n"; //error: within this contextreturn os;}std::istream& operator>>(std::istream& is, Date& dat){std::cout << "input day: "; //error: within this contextis >> dat.d;std::cout << "input month: "; //error: within this contextis >> dat.m;std::cout << "input year: "; //error: within this contextis >> dat.y;if (check_date(dat)) //error: 'check_date' was not declared in this scope| return is;} Quote Link to comment Share on other sites More sharing options...
Darhazer Posted May 26, 2010 Report Share Posted May 26, 2010 Во первых, check_date() не функция, а метод класа dat, так что вам нужно dat.check_date(); А лучше сделать check_date static? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.