#include<iostream>
using namespace std;
class Date {
private:
int year;
int month;
int day;
public:
Date();
Date(int y, int m, int d);
Date(Date& D);
void setDate(int year, int month, int day) {
this->year = year;
this->month = month;
this->day = day;
}
void showDate();
};
Date::Date() :year(2021), month(4), day(16) {
}
Date::Date(Date& D) {
year = D.year;
month = D.month;
day = D.day;
}
inline void Date::showDate() {
cout << year << "/" << month << "/" << day << endl;
}
int main()
{
Date d1;
d1.showDate();
Date d2(2021, 3, 13);
d2.showDate();
d2.setDate(2021, 5, 1);
d2.showDate();
Date d3(d1);
d3.showDate();
return 0;
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/279401.html
標籤:C++ 語言
上一篇:對c++拷貝建構式的疑問
