源程序:
#include
class Rectangle
{
public:
Rectangle (int top, int left, int bottom,int right);
~Rectangle () {}
int GetTop() const { return itsTop; }
int GetLeft() const { return itsLeft; }
int GetBottom() const { return itsBottom; }
int GetRight() const { return itsRight; }
void SetTop(int top) { itsTop = top; }
void SetLeft (int left) { itsLeft = left; }
void SetBottom (int bottom) { itsBottom =bottom; }
void SetRight (int right) { itsRight =right; }
int GetArea() const;
private:
int itsTop;
int itsLeft;
int itsBottom;
int itsRight;
};
Rectangle::Rectangle(int top, int left, intbottom, int right)
{
itsTop = top;
itsLeft = left;
itsBottom = bottom;
itsRight = right;
}
int Rectangle::GetArea() const
{
int Width = itsRight-itsLeft;
int Height = itsTop - itsBottom;
return (Width * Height);
}
int main()
{
RectangleMyRectangle (100, 20, 50, 80 );
int Area = MyRectangle.GetArea();
cout << "Area: " <return 0;
}
程序运行输出:
Area: 3000
Upper Left X Coordinate: 20
有几点疑惑,求大神解释:
1.~Rectangle () {}这个析构函数具体有什么用?
2.int GetTop() const { return itsTop; } const有什么含义
3.
void SetTop(int top) { itsTop = top; }
void SetLeft (int left) { itsLeft = left; }
void SetBottom (int bottom) { itsBottom =bottom; }
void SetRight (int right) { itsRight =right; }
itsTop = top itsLeft = left itsBottom =bottom 是什么意思
4.还有一种表达方式是this->top=top 这里的this表示什么 有什么用法?