所以我很好奇下面的代碼崩潰的原因。 會感謝您的幫助。你能告訴我爲什麼這段代碼崩潰了?
#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