请帮忙看看 class里面哪里错了,class下面的主函数不能改
c吧
全部回复
仅看楼主
level 4
橘安nn 楼主
#include <iostream>
using namespace std;
class Rectangle {
public:
void setLength() {
cin>> length;
}
void setWidth() {
cin>> width;
}
void Area() {
cin >> length >> width;
s = length * width;
cout << s << endl;
}
private:
int length;
int width;
int s;
};
int main() {
int length, width;
cin >> length >> width;
Rectangle rect;
rect.setLength(length);
rect.setWidth(width);
cout << rect.returnArea() << endl;
}
2022年10月12日 09点10分 1
level 1
setWidth(这里没参数),后面main里rect.setWidth(width)是错误的。
2022年10月12日 09点10分 2
不太理解,为什么没参数啊,那个cin>> width对吗
2022年10月12日 14点10分
1