我看到了这段代码。在析构函数之后使用 : int area () {return (*width * *height);} 是否有效?
// example on constructors and destructors
#include <iostream>
using namespace std;
class CRectangle {
int *width, *height;
public:
CRectangle (int,int);
~CRectangle ();
int area () {return (*width * *height);}
};
CRectangle::CRectangle (int a, int b) {
width = new int;//
height = new int;//
*width = a;//
*height = b;//
}//
CRectangle::~CRectangle (){//
delete width;//
delete height;//
}////