Home > Back-end >  C function problem
C function problem

Time:04-06

#include
#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; Int main ()
{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 member

CodePudding user response:

Is not a friend function can be called directly

CodePudding user response:

reference 1st floor focuslight response:
PLG. The name -- -- -- -- -- -- -- -- -- like this call private member is not enough, add the get function obtains the private member right
is not a friend function can be called directly

CodePudding user response:

See comments, for your reference:
 # include & lt; Iostream> 
#include
#include
using namespace std;

The class Boy;

The class Girl
{
Public: Girl (char N [], int A);

Friend void prdata (const Girl & amp; PLG, const Boy & amp; PLB);
//friend void prodata (const Girl & amp; PLG, const Boy & amp; PLB);
Private: char name [25];
Int the age;
};

Girl: : Girl (char N [], int A)
{
Strcpy (name, N);
Age=A;
}

The class Boy
{
Public: Boy (char N [], int A);

Friend void prdata (const Girl & amp; PLG, const Boy & amp; PLB);

Private: char name [25];
Int the 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; Cout<& lt;" Girl 's age: "& lt; Cout<& lt;" The boy 's name: "& lt; Cout<& lt;" The boy 's age: "& lt; }


Int main ()
{
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;
}

CodePudding user response:

The Girl in the class, a friend function name is different, more than a 'o' :
 friend void prdata (const Girl & amp; PLG, const Boy & amp; PLB); 
//friend void prodata (const Girl & amp; PLG, const Boy & amp; PLB);

CodePudding user response:

Void prdata (const Girl & amp; PLG, const Boy & amp; (PLB) prdata spelling wrong friend void prdata const Girl PLG, const Boy & amp; PLB);

CodePudding user response:

You are prodata written statement

CodePudding user response:

thank you very much!

CodePudding user response:

reference 5 floor QZJHJXJ reply:
the Girl in the class, a friend function name is different, more than a 'o' :
 friend void prdata (const Girl & amp; PLG, const Boy & amp; PLB); 
//friend void prodata (const Girl & amp; PLG, const Boy & amp; PLB);
thank you very much!
  • Related