Код:
# include <iostream>
using namespace std;
class rectangle
{
private:
double length;
double width;
public:
rectangle() { assign(0,0); };
rectangle(double Len,double Wide) { assign(Len,Wide); };
double Length() { return length; };
double Width() { return width; };
double Area() { return length*width; };
void assign(double Len,double Wide);
};
void rectangle::assign(double Len,double Wide)
{
length=Len;
width=Wide;
}
int main()
{
rectangle rect;
double len,wid;
cout<<"Введите длину прямоугольника : "; cin>>len;
cout<<"Введите ширину прямоугольника: "; cin>>wide;
rect.assign(len,wide);
cout<<" Введеная длина ="<<rect.Length()<<"\n";
cout<<" Введеная ширина ="<<rect.Width()<<"\n";
cout<<" Площадь прямоугольника = "<<rect.Area()<<"\n";
return 0;
} Однако компилятор g++ выдает ошибки :
Код:
rect.cpp:14: error: declaration of ‘double rectangle::length()’
rect.cpp:10: error: conflicts with previous declaration ‘double rectangle::length’
rect.cpp:15: error: declaration of ‘double rectangle::width()’
rect.cpp:11: error: conflicts with previous declaration ‘double rectangle::width’
rect.cpp: In member function ‘double rectangle::length()’:
rect.cpp:14: error: argument of type ‘double (rectangle:
()’ does not match ‘double’
rect.cpp: In member function ‘double rectangle::width()’:
rect.cpp:15: error: argument of type ‘double (rectangle:
()’ does not match ‘double’
rect.cpp: In member function ‘double rectangle::area()’:
rect.cpp:16: error: invalid use of member (did you forget the ‘&’ ?)
rect.cpp:16: error: invalid use of member (did you forget the ‘&’ ?)
rect.cpp: In member function ‘void rectangle::assign(double, double)’:
rect.cpp:22: error: invalid use of member (did you forget the ‘&’ ?)
rect.cpp:23: error: invalid use of member (did you forget the ‘&’ ?)
rect.cpp: In function ‘int main()’:
rect.cpp:31: error: ‘wide’ was not declared in this scope
Я уже что только не менял, но все равно не могу найти ошибки.
P.S. Программирую на C++ две недели. Ubuntu 6.10 .