65,164
社区成员




#include<iostream>
using namespace std;
class Date{
int m_y;
int m_m;
int m_d;
public:
Date();
Date(int y,int m,int d){
m_y=y;
m_m=m;
m_d=d;
}
public:
void set(int y,int m,int d){
m_y=y;
m_m=m;
m_d=d;
}
friend Date operator+(const Date& d1,const Date& d2){
Date d;
d.set(d1.m_y+d2.m_y,d1.m_m+d2.m_m,d1.m_d+d2.m_d);
return d;
}
void display(){
cout<<"The date is:"<<m_y<<","<<m_m<<","<<m_d<<endl;
}
};
int main(){
Date d1(2009,11,10);
d1.display();
Date d2(1,1,1);
d2.display();
(d1+d2).display();
}
Date()
{
};//改成这样