📄 402.cpp
字号:
/*
402.cpp
Written By S.Y.Feng
demo using new and delete
*/
#include <iostream.h>
class Point // define Point class
{
int x; // x and y are private by default
int y;
public:
Point(){ x = 0; y = 0 ;}
Point(int a,int b=0) { x = a; y= b; }
void Display()
{
cout << "x = "<< x
<< " y = "<< y << endl;
}
~Point() {cout << "Destruct obj.\n" ;}
};
int main()
{
Point *p;
p=new Point(1,3);
if(!p)
{ cout << "allocation failure\n"; return -1; }
p->Display();
delete p;
return 0;
}
/*
x = 1 y = 3
Destruct obj.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -