我在这里做了一个测试,但输出是一个没有结束的循环,我不知道为什么。构造函数中的无限循环没有for或while
其实,我正在做另一个测试,但是当我写这个时,我不明白循环是怎么发生的。它反复输出“ABC”。
#include <map>
#include <string>
#include <iostream>
class test
{
public:
std::map <int, int> _b;
test();
test (std::map<int, int> & im);
~test();
};
test::test()
{
std::cout<<"abc";
_b.clear();
_b[1]=1;
test(_b);
}
test::test(std::map <int, int>& im)
{
std::cout<<im[1];
}
test::~test() {};
int main()
{
test a;
}
由于'test(_b)'的递归;'但我不确定原因。 – Roddy 2013-04-24 20:07:08
@ Roddy-我只是想通了;详情请参阅我的答案。 – templatetypedef 2013-04-24 20:09:14
已删除不重要的内容的清理版本:http://ideone.com/z0yc7Q – Yakk 2013-04-24 20:15:33