标签:
#include<iostream> using namespace std; class area { public: area(int l,int w){length=l;width=w;cout<<"调用构造函数,设置长和宽:"<<length<<"\t"<<width<<endl;} ~area(){cout<<"调用析构函数释放内存,此时长和宽:"<<length<<"\t"<<width<<endl;} int get(){return length*width;} void set(int l,int w){length=l;width=w;} private: int length,width; }; int main() { area one[4]={area(10,10),area(13,34),area(20,30),area(40,40)}; cout<<one[0].get()<<endl; one[0].set(30,40); cout<<one[0].get()<<endl; cout<<one[1].get()<<endl; cout<<one[2].get()<<endl; cout<<one[3].get()<<endl; return 0; }
标签:
原文地址:http://blog.csdn.net/u012503639/article/details/42969779