C + + is not purely object-oriented

Source: Internet
Author: User

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=" <

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.