C + + is not a complete object-oriented language, but a hybrid product.
If a function is declared as friend, it means that it is not a member function of the class, but can modify the private member of the function, and must be listed in the definition of the class, so it can be considered a privileged function
#include "iostream"
#include "CString"
using namespace Std;
const int SZ=20;
struct Holder
{
Private
int A[sz];
Public
void Initialize ();
struct Pointer;
Friend Pointer;
struct pointer{
Private
holder* h;
int* p;
Public
void Initialize (holder* h);
void Next ();
void Previous ();
void Top ();
void End ();
int read ();
void set (int i);
};
};
void Holder::initialize ()
{
memset (A,0,SZ * sizeof (int));
}
void Holder::P ointer::initialize (holder* RV)
{
h = RV;
p = rv->a;
}
void Holder::P ointer::next ()
{
if (p<& (H->a[sz-1]))
{
p++;
}
}
void Holder::P ointer::p revious ()
{
if (p>& (h->a[0]))
{
p--;
}
}
void Holder::P ointer::top ()
{
p=& (H->a[0]);
}
void Holder::P ointer::end ()
{
p=& (H->a[sz-1]);
}
int Holder::P ointer::read ()
{
return *p;
}
void Holder::P ointer::set (int i)
{
*p =i;
}
int main ()
{
Holder h;
Holder::P ointer hp,hp2;
int i;
H.initialize ();
Hp.initialize (&H);
Hp2.initialize (&H);
for (i=0;i<sz;i++)
{
Hp.set (i);
Hp.next ();
}
Hp.top ();
Hp2.end ();
for (i=0;i<sz;i++)
{
cout<< "hp=" <