#include<iostream>
using namespace std;
class DayOfYear{
public:
DayOfYear();
DayOfYear(const DayOfYear&);
DayOfYear(int m,int d);
friend bool equel(DayOfYear today,DayOfYear bach_birthday); //友元函数声明
void input(){cin>>year>>month>>day;}
void output(){cout<<year<<"年"<<month<<"月"<<day<<"日"<<endl;}
int year;
int month;
int day;
};
DayOfYear::DayOfYear(int m,int d)
{
month=m;
day=d;
}
DayOfYear::DayOfYear(const DayOfYear& comp)
{
month=comp.month;
day=comp.day;
}
bool equal(DayOfYear today,DayOfYear bach_birthday){ //友元函数实现
if((today.month==bach_birthday.month) && (today.day==bach_birthday.day))
return true;
else
return false;
}
int main()
{
DayOfYear today,bach_birthday(3,21);
cout<<"Enter today's date:"<<endl;
today.input();
cout<<"Today's date is";
today.output();
cout<<"Your birthday is";
bach_birthday.output();
if(equal(today,bach_birthday))
cout<<"Happy Birthday to You!"<<endl;
else
cout<<"Happy Unbirthday to you!"<<endl;
return 0;
}
C++出现undefined reference to `DayOfYear::DayOfYear()'咋改???
最新推荐文章于 2020-11-28 07:50:31 发布