I am not fully sure on the way that friend functions work and need help fixing/understanding the friend function "printNumbers" in my code.
Header File:
class Date
{
// friend Date printText(Date);
friend Date printNumbers(Date);
public: // Functions available for clients use.
Date(); // Class constructor
void increaseDate(int monthHolder, int dayHolder, int yearHolder);
void insertDate(int monthHolder, int dayHolder, int yearHolder);
private: // Can only be used within the class, Client cannot call it.
int month, day, year;
};
cout << "Enter '1' to increase day then 'n' to output number format or 'w'"
<< "to output word format(ex: 1 w or 1 n). To exit enter 0."
<< endl;
cin >> cont >> printType;
}
else{
cout << "invalid input. Choose 'n' or 'w'." << endl;
}
cout << "continue(1 for yes, 0 for no)?: ";
cin >> cont;
if ( cont == 1 ){
cout << "Choose print format(w or n): ";
cin >> printType;
}
}
return 0;
}
Alright, my goal for this friend function is to print out the values being held in the private section of the Date class in the format of: month / day / year(ex: 10 30 2003). I keep getting errors like i cannot access the int because it is private. There is more to my Date.cpp file but none of it has to do with this problem, so i left it out to make the code shorter. How do i write the friend function so that i can print out the values in the Date.h private section? I have to use a friend function to do this because it is one of the requirements to this project but i cannot seem to figure out how friend functions work.