一个析构函数的问题
一个简单的矩形的类为什么~Rectangle()里的 cout <<"End......."<<"\n";不打印?
才学C++没几天。。请教。。。
程序代码:
#include<iostream> using namespace std; class Rectangle { public: Rectangle(); Rectangle(int,int); ~Rectangle(); void Draw(); int Rect(); private: int itslength; int itsheight; }; Rectangle::Rectangle() { itslength=8; itsheight=6; } Rectangle::Rectangle(int length,int height) { itslength=length; itsheight=height; } Rectangle::~Rectangle() { cout <<"End......."<<"\n"; } void Rectangle::Draw() { for(int i=1;i<=itsheight;i++) { for(int j=1;j<=itslength;j++) cout<<"*"; cout<<"\n"; } } int Rectangle::Rect() { cout<<"面积="<<itslength*itsheight<<"\n"; cout<<"周长=" <<2*(itslength+itsheight)<<"\n"; } int main(void) { Rectangle rect1; Rectangle rect2(20,15); rect1.Draw(); rect1.Rect(); rect2.Draw(); rect2.Rect(); getchar(); return 0; }