#include <iostream>
using namespace std;
class Line
{
public:
void setLength( double len );
double getLength( void );
Line(double len);
private:
double length;
};
Line::Line( double len)
{
cout << "Object is being created, length = " << len << endl;
length = len;
}
void Line::setLength( double len )
{
length = len;
}
double Line::getLength( void )
{
return length;
}
int main( )
{
Line line(10.0);
cout << "Length of line : " << line.getLength() <<endl;
line.setLength(6.0);
cout << "Length of line : " << line.getLength() <<endl;
return 0;
}
Line line(10.0);
cout << "Length of line : " << line.getLength() <<endl;
输出值为10,这里getLength()是直接从LINE构造函数中取得length值吗?
line.setLength(6.0);
cout << "Length of line : " << line.getLength() <<endl;
这里getLength()是从setLength函数中取length值吗?