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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

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