Jump to content

помогите исправить ошибку в коде С++


Recommended Posts

Объявление класса:

 #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;}
Link to comment
Share on other sites

Во первых, check_date() не функция, а метод класа dat, так что вам нужно

dat.check_date();

А лучше сделать check_date static?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...