this point

clip_image001

clip_image002

clip_image003

// this.cpp : 定义控制台应用程序的入口点。

//

#include "stdafx.h"

#include<iostream>

using namespace std;

class A

{

public:

A() { i = 0; }

void add() { i++;}

A*sp() { return this; }

int Is(A*s) { return s->i; }

private:

int i;

};

A*p[2];

int main()

{

A a1, *a2 = new A;

p[0] = a1.sp();

p[1] = a2;

p[0]->add();

a2->add();

p[1]->add();

cout << "i--a1:" << p[1]->Is(p[0])<<endl<< "i--a2:" << p[0]->Is(p[1]) << endl;

system("pause");

return 0;

}

clip_image004

原文地址:https://www.cnblogs.com/summercloud/p/5537546.html