課程
/后端開發
/C++
/C++遠征之封裝篇(上)
為什么后面釋放p內存的時候會編譯出錯,顯示標識符未被定義?
2019-08-21
源自:C++遠征之封裝篇(上) 2-2
正在回答
delete P 這個“P”是大些的,前面的是小寫的,所以說這個大寫的“P”沒有定義
#include <iostream>
using namespace std;
class Coordinate
{
public:
? ? int x;
? ? int y;
? ? void printX()
? ? {
? ? ? ? cout << x << endl;
? ? }
? ? void printY()
? ? ? ? cout << y << endl;
};
int main()
? ? Coordinate coor;
? ? coor.x=10;
? ? coor.y=20;
? ? coor.printX();
? ? coor.printY();
? ? Coordinate *p=new Coordinate();
? ? if(p==NULL)
? ? ? ? return 0;
? ? p->x=100;
? ? p->y=200;
? ? p->printX();
? ? p->printY();
? ? delete P;
? ? p=NULL;
? ? return 0;
}
它定義的不是str嗎。。。沒有p啊。。。
周周周3716585 提問者
慕妹24344680 回復 周周周3716585 提問者
舉報
封裝--面向對象的基石,本教程力求幫助小伙伴們即學即會
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2019-10-29
delete P 這個“P”是大些的,前面的是小寫的,所以說這個大寫的“P”沒有定義
2019-08-24
#include <iostream>
using namespace std;
class Coordinate
{
public:
? ? int x;
? ? int y;
? ? void printX()
? ? {
? ? ? ? cout << x << endl;
? ? }
? ? void printY()
? ? {
? ? ? ? cout << y << endl;
? ? }
};
int main()
{
? ? Coordinate coor;
? ? coor.x=10;
? ? coor.y=20;
? ? coor.printX();
? ? coor.printY();
? ? Coordinate *p=new Coordinate();
? ? if(p==NULL)
? ? {
? ? ? ? return 0;
? ? }
? ? p->x=100;
? ? p->y=200;
? ? p->printX();
? ? p->printY();
? ? delete P;
? ? p=NULL;
? ? return 0;
}
2019-08-21
它定義的不是str嗎。。。沒有p啊。。。