下面的代码永远不会打印出计数器,假设编译器做了一些智能的事情来将 int 数据成员类型初始化为零?
include <iostream>
using namespace std;
class A {
public:
int a;
int b;
A(): b(a), a(b) { }
};
int main()
{
A* p = new A;
int counter = 0;
while (!(p->a)) {
p = new A;
counter++;
}
cout << counter << endl;
}