1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include<iostream> using namespace std; class area { private: int length, width; public: area() {length = 0, width = 0;} ~area() {cout << "调用析构函数释放内存"<< endl;} void set(int l, int w) { length = l; width = w; } int get() {return length * width;} }; using namespace std; int main() { area *one=new area[10000]; for (int i = 0; i < 10000; i++) { one[i].set(4,5); } cout << "area[" << 1 << "]" << one[1].get() << endl; // for(int i=0;i<10000;i++){ // delete one[i]; // } delete []one; return 0; }
|