这个代码哪里有错误?发现不出来

来源:百度知道 编辑:UC知道 时间:2024/06/15 09:35:08
#include <iostream.h>

class Rectangle
{
Rectangle();
~Rectangle();
void SetLength(int length) {this -> itsLength = length;}
int GetLength() const {return this -> itsLength;}
void SetWidth(int width) {this -> itsWidth = width;}
int GetWidth() const {return itsWidth;}

private:
int itsLength;
int itsWidth;

};

Rectangle::Rectangle()
{
itsWidth = 5;
itsLength = 10;
}

Rectangle::~Rectangle()

int main()
{
Rectangle theRect;
cout << "theRect is " << theRect.GetLength() << " feet long.\n";
cout << "theRect is " << theRect.GetWidth() << " feet wide.\n";
theRect.SetLength(20);
theRect.SetWidth(10);
cout << "theRect is " << theRect.GetLength() << " feet long.\n";
cout <&l

Rectangle::~Rectangle() 这句出现编译过去,但是到连接时出错,如果再下面的定义Rectangle::~Rectangle()改为Rectangle::~Rectangle(){}就可以了,初学者都出现这样的错误,我也出现过这样的错误,不过学习的时间久了就有经验了,记住,一定要让析构函数定义,就是必须在其后加{}及时是空的,但是它的意义就是一个函数,而不是你写的那样。

郁闷,公司里没C++调试环境。。