预期是输出1 2 3 4。但结果为一个奇怪的数不停循环。
```c++
#include<iostream>
using namespace std;
class A
{
public:
A* next;
int data;
A()
{
data = 0;
next= NULL;
}
};
class B
{
public:
A* head;
void init()
{
head = new A();
}
void add(A a)
{
A* point = head;
while (point->next != NULL)
{
point = point->next;
}
point->next = &a;
}
};
class C
{
public:
void cb(B b)
{
for (int i = 0; i < 4; i++)
{
A a = A();
a.data = i+1;
b.add(a);
}
}
};
int main()
{
B b;
b.init();
C c;
c.cb(b);
A* point = b.head;
while ((point->next)!=NULL)
{
cout << point->next->data << endl;
}
}