Home > Back-end >  C class template of zhongyou metaclass friends function cannot access to their private variables?
C class template of zhongyou metaclass friends function cannot access to their private variables?

Time:09-27

#include
using namespace std;

The template & lt; The class T>
Class A;
template
Class B;
template Void print1 (A & lt; T> & A1, B & B1);


The template & lt; The class T>
Class A
{
Public:
A (int A) : (A) x
{


}
Friend class B;


Private:
int x;


};

template
Class B
{
Public:
B (int) B: y (B)
{


}


Friend void print1 (A & lt; T> & A1, B & B1)
{
Cout & lt; }


Private:
int y;
};

In the template class A friends add A metaclass B, A friend function is added in the B print1, but not in print1 access A private variable, it can be fully proved that friends do not have sex?

CodePudding user response:

Learn best friend without first template for example,

This can be fully proved that friends do not have sex?
If taken literally, the sufficient condition of the so-called cannot just one example can prove,
And friends don't have passed this don't need to prove, it is a mandatory standard regulation, is no proof,

You can say, this example illustrates a friend would not be delivered?
I can only say that this is not a good example,
  • Related