Pass the program, what circumstance, please advice
# include using namespace std; The class CDate;//class reference in advance statement
The class CTime { Public: CTime (int h, m int, int) s: hour (h), minute (m), second (s) {} Friend void CDate: : display (CTime t);//declare the CDate display function as friend yuan Void the display () { cout} Private: Int hour; Int minute; Int second; }; The class CDate { Public: CDate (int y, int m, int d) : the year (y), month (m), date (d) {} Void the display (CTime t) { T.d isplay (); cout} Private: Int year; Int the month; Int the date; };
Int main () { CTime t,11,11 (11); CDate d (12,12,12); D.d isplay (t); system("pause"); return 0; }
CodePudding user response:
I think you are understanding of a friend is not quite right, Void display CTime (t)//use the parameter t, t.d isplay () call don't need a friend The class is not used in CTime CDate: : the display, so a friend declaration is unnecessary