8_8.cpp
来自「C++语言程序设计案例教程,郑莉编的书」· C++ 代码 · 共 17 行
CPP
17 行
#include <iostream>
using namespace std;
#include <malloc.h>
class CRect
{ int length,width;
public:
CRect(int l,int w) {length=l; width=w; }
void disp() { cout << "The area is:" << length*width << endl;}
void *operator new(size_t size) { return malloc(size);} //语句1:重载new
void operator delete(void *p) { free(p); } //语句2:重载delete
};
int main ()
{ CRect *p; //定义对象指针
p=new CRect(5, 9) ; p->disp () ; delete p;//使用重载的new和delete
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?