一个关于静态成员的链表模型
jamesji----->colin----->marry----->NULL
0012ff28 0012ff4c 00371bb8
point[0012ff28]
jamesji----->colin----->NULL
0012ff28 0012ff4c
point[0012ff28]
////////////////////////////////////////////////////
#include <iostream>
using namespace std;
class Student
{
public:
Student(char* name);
~Student();
public:
char name[30];
Student* next;
static Student* point;
};
Student::Student(char* name)
{
strcpy(Student::name, name);
this->next = point;
point = this;
cout<< name << endl;
cout << "this: " << this << endl;
cout << "this->next: " << this->next << endl;
cout << "point: " << point << endl ;
cout << "point->next: " << point->next << endl << endl;
}
Student::~Student()//析构过程就是节点的脱离过程
{
cout << "析构:" << name << endl;
cout << "this: " << this << endl;
cout << "this->next: " << this->next << endl;
cout << "point: " << point << endl ;
cout << "point->next: " << point->next << endl << endl;
if (point == this)
{
point = this->next;
cin.get();
return;
}
for (Student* ps = point; ps; ps = ps->next)
{
cout << "ps: " << ps << "\tpoint: " << point <<endl;
if (ps->next == this)
{
cout << "执行过Student* ps = point:" << endl;
cout << "ps->next: " << ps->next << " | "
<< "ps: " << ps << " | "
<< "this->next: " << this->next << " | "
<< "this: " << this << endl;
ps->next = this->next;//=next也可以写成this->next;
cin.get();
return;
}
}
cin.get();
}
Student* Student::point = NULL;
void main(void)
{
Student* c = new Student("marry");
Student a("colin");
Student b("jamesji");
delete c;
Student* fp = Student::point;
while (fp != NULL)
{
cout << fp->name << endl;
fp = fp->next;
}
cin.get();
}


浙公网安备 33010602011771号