-1
我的代碼編譯爲這樣,但我不明白爲什麼我一直得到這個錯誤告訴我,「調試斷言失敗」。爲什麼是這樣?調試斷言失敗(動態類型變量)
#include <iostream>
using namespace std;
struct Bag
{
int k;
};
int main()
{
int *p1;
int *p2;
char p3;
//k = 100; // Assigns variable of type bag to 100
p1 = new int; // Variables created using the new operator are called dynamic variables
p2 = new int;
*p1 = 30;
*p2 = 50;
p3 = 'K';
*p1 = *p1 + *p2;
p1 = p2;
cout << "The sum of the two pointers is = " << *p1 << endl;
delete p1;
delete p2; // Delete the dynamic variable p1 and return the memory occupied by p1 to the freestore to be reused.
system ("Pause");
return 0;
}
它也泄漏了原來由p2指向的內存。 –