// Code derived from Stroustrup's PPP2 book
// § 9.7.2 Copying
// -and beginning on p 326
#include <iostream>
using namespace std;
enum class Month {
jan = 1,
feb,
mar,
apr,
may,
jun,
jul,
aug,
sep,
oct,
nov,
dec
};
// simple Date (use Month type):
class Date {
public:
Date(int yy, Month mm, int dd) : y{yy}, m{mm}, d{dd}
{
// initialize & check for valid date
// ...
}
friend ostream& operator<<(ostream& os, const Date& d)
{
return os << '{' << d.y << ',' << int(d.m) << ',' << d.d << '}';
}
private:
int y; // year
Month m;
int d; // day
};
int main()
{
Date holiday{1978, Month::jul, 4}; // initialization
[[maybe_unused]] Date d2 = holiday;
Date d3 = Date{1978, Month::jul, 4};
holiday = Date{1978, Month::dec, 24}; // assignment
d3 = holiday;
cout << Date{1978, Month::dec, 24} << '\n';
}