所以我很好奇下面的代码崩溃的原因。 会感谢您的帮助。你能告诉我为什么这段代码崩溃了?
#include <iostream>
using namespace std;
class temp
{
public:
temp(int i)
{
intPtr = new int(i);
}
~temp()
{
delete intPtr;
}
private:
int* intPtr;
};
void f (temp fInput)
{
cout << "f called" << endl;
}
int main()
{
temp x = 2;
f(x);
return 0;
}
你能定义“崩溃”吗? – josephthomas 2012-04-04 21:18:44
@ Ed S:但是,我同意,有时候我们认为的崩溃可能与他认为的崩溃不同。 – josephthomas 2012-04-04 21:23:02
@josephthomas:是的,我想到了很多,这就是为什么我发布后不久就删除了我的评论:)我们可以就术语的正确使用达成一致......是否大多数初学者会正确使用它是另一个问题 – 2012-04-04 21:23:41