我不希望这是我的第一篇文章,但我在这里不知所措。尝试编译我的程序时,我不断收到此错误(它应该只是找到矩形的面积和周长。)这是我的头文件。
#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle(float Lngth=1, float Wdth = 1);
void setLngth(float Lngth);
void setWdth(float Wdth);
float getLngth(float Lngth);
float getWdth(float Wdth);
void Perimeter(float lngth, float wdth);
void Area(float lngth, float wdth);
private:
float Lngth;
float Wdth;
};
这是我的 .cpp 文件。
#include <iostream>
using namespace std;
#include "RealRectangle.h" // Employee class definition
Rectangle::Rectangle(float Lngth, float Wdth)
{
&Rectangle::setLngth;
&Rectangle::setWdth;
}
void Rectangle::setLngth(float Lngth)
{
if((Wdth > 0.0) && (Wdth < 20.0))
float wdth = Wdth;
else
cout<<"Invalid Width."<<endl;
}
float Rectangle::getLngth(float Lngth)
{
return Lngth;
}
void Rectangle::setWdth(float Wdth)
{
if((Wdth > 0.0) && (Wdth < 20.0))
float wdth = Wdth;
else
cout<<"Invalid Width."<<endl;
}
float Rectangle::getWdth(float Wdth)
{
return Wdth;
}
void Rectangle::Perimeter(float lngth, float wdth)
{
cout<<"The Perimeter is "<<(2*(lngth + wdth));
}
void Rectangle::Area(float lngth, float wdth)
{
cout<<"The Area is "<<(lngth * wdth);
}
这就是我不断遇到错误的地方。编译器告诉我添加一个与号来创建一个指针,就像我在 .cpp 中所做的那样。但这本身就会产生另一个错误。等等。我不确定我做错了什么。错误发生在第 10 行和第 11 行。
#include <iostream>
using namespace std;
#include "RealRectangle.h"
int main()
{
Rectangle rectangle1();
Rectangle rectangle2();
cout<<rectangle1.Perimeter();
cout<<rectangle2.Area();
}