Im supposed to turn this function into a friend function but im having trouble doing it. I could only know how to convert the function declaration into a friend but i dont know how to do it to the function. Can someone please help me fix it or give me some advice on what i should be doing.
#include <iostream.h>
#include <conio.h>
class Date
{
private:
int month;
int day;
int year;
public:
Date(int = 7, int = 4, int = 2001);
friendintoperator==(const Date &);
};
Date::Date(int mm, int dd, int yyyy)
{
month = mm;
day = dd;
year = yyyy;
}
int Date::operator==(const Date &date2)
{
if(day == date2.day && month == date2.month && year == date2.year)
return 1;
elsereturn 0;
}
int main ()
{
Date a(4, 1, 1999), b(12, 18, 2001), c(4, 1, 1999);
if (a == b)
cout << "\nDates a and b are the same." << endl;
else
cout << "\nDates a and b are not the same." << endl;
if (a == c)
cout << "Dates a and c are the same.\n" << endl;
else
cout << "Dates a and c are not the same.\n" << endl;
getch();
return 0;
}