#include
#include
using namespace std;
The class Boy;
The class Girl
{
Public: Girl (char N [], int A); Friend void prodata (const Girl & amp; PLG, const Boy & amp; PLB);
Private: char name [25]; int age;
};
Girl: : Girl (char N [], int A)
{strcpy (name, N); Age=A;
}
The class Boy
{
Public: Boy (char N [], int A); Boy friend void prdata (const Girl PLG, const & amp; PLB);
Private: char name [25]; int age;
};
Boy: : Boy (char N [], int A)
{strcpy (name, N); Age=A;
}
Void prdata (const Girl & amp; PLG, const Boy & amp; PLB)
{cout<& lt;" Girl 's name: "& lt;
{Girl g1 (SSM, 12); Girl g2 (" xiaohu, 13); Girl g3 (" XLB ", 12); Boy b1 (" gala8 ", 13); Boy b2 (" ycw ", 12); Boy b3 (" wei ", 14); Prdata (g1, b1); Prdata (g2, b2); Prdata (g3, b3); return 0;
} why PLG PLB call not?
CodePudding user response:
PLG. Name -- -- -- -- -- -- -- -- -- like this call private member is not enough, add the get function obtained private memberCodePudding user response:
Is not a friend function can be called directlyCodePudding user response: