/*下面的程序似乎神秘地进入了递归,尽管看不到递归。 编译器:g++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3 机器:x86 操作系统:Ubuntu 10.04 64位
*/
#include<iostream>
using namespace std;
class Test
{
public:
Test ():x(9)
{
cout << " Test::Test\n";
Test (x);
}
Test (int a)
{
cout << " Test::para\n";
}
private:
int x;
};
int main(void)
{
Test a;
return 0;
}
这是为什么?
最佳答案
Test (x);
被解析为
Test x;
...不是构造函数调用。 你也可以这样写
Test (y);
并获得相同的行为。
关于c++ - 默认构造函数递归崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10813560/