钱能C++上抄的,为什么还有错??

来源:百度知道 编辑:UC知道 时间:2024/07/02 06:30:07
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class Date
{
int year,month,day;
protected:
int ymd2i()const;
void i2ymd(int n);
void print(ostream& o)const;
static const int tians[]={ 0, 31, 59, 89, 120, 150, 181, 212, 242, 273, 303, 334 };
bool isLeapYear()const
{
return!(year%4)&&(year%100)||!(year%400);
}
public:
Date(const string& s);
Date(int n=1){i2ymd(n);}
Date(int y,int m,int d):year(y),month(m),day(d){}
Date operator+(int n)const
{
return Date(ymd2i()+n);
}
Date& operator+=(int n)
{
i2ymd(ymd2i()+n);return *this;
}
Date& operator++()
{
return *this+=1;
}
int operator-(Date& d)const
{
return ymd2i()-d.ymd2i();
}
friend ostream& operator<<(ostream& o,const Date& d);
};
Date::Date(const string& s)
{

1.static不要在类里面定义(声明可以)
2.void print(ostream& o)const
这里你抄错了
3.友元的问题vc6.0支持不好,g++编译没问题.
修改如下(for vc6.0):
#include<iostream>
#include<iomanip>
#include<string>
static const int tians[]={ 0, 31, 59, 89, 120, 150, 181, 212, 242, 273, 303, 334 };
using namespace std;
class Date
{
int year,month,day;
public:
void print(ostream& o)const;
protected:
int ymd2i()const;
void i2ymd(int n);

bool isLeapYear()const
{
return!(year%4)&&(year%100)||!(year%400);
}
public:
Date(const string& s);
Date(int n=1){i2ymd(n);}
Date(int y,int m,int d):year(y),month(m),day(d){}
Date operator+(int n)const
{
return Date(ymd2i()+n);
}
Date& operator+=(int n)
{
i2ymd(ymd2i()+n);return *this;
}
Date& operator++()
{
return *this+=1;
}
int operator-(Date& d)const
{