哪里有错误啊?#includeusing namespace std;class Rectangle{public:{int width,height;}private:{ void r2(int w,int h)int area()};void Rectangle::r2(int w,int h){width=w;height=h;}Rectangle::area() {return width * height;}int main(){Rectangle r1r1.r

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 17:06:58
哪里有错误啊?#includeusingnamespacestd;classRectangle{public:{intwidth,height;}private:{voidr2(intw,inth)i

哪里有错误啊?#includeusing namespace std;class Rectangle{public:{int width,height;}private:{ void r2(int w,int h)int area()};void Rectangle::r2(int w,int h){width=w;height=h;}Rectangle::area() {return width * height;}int main(){Rectangle r1r1.r
哪里有错误啊?
#include
using namespace std;
class Rectangle
{
public:
{int width,height;}
private:
{ void r2(int w,int h)
int area()
};
void Rectangle::r2(int w,int h)
{width=w;height=h;}
Rectangle::area() {return width * height;}
int main()
{
Rectangle r1
r1.r2(3,5) ;
cout

哪里有错误啊?#includeusing namespace std;class Rectangle{public:{int width,height;}private:{ void r2(int w,int h)int area()};void Rectangle::r2(int w,int h){width=w;height=h;}Rectangle::area() {return width * height;}int main(){Rectangle r1r1.r
1、我实在搞不懂,你都已经会写类了,居然还会忘了写分号
很多地方,我就不一一列举了
2、属性设为私有,方法设有公有.你却恰好相反,另外公有私有不要用大括号括起来,放在后面系统就会分辨.
3、 Rectangle::area() {return width * height;}前面少了函数类型int
编程要细心.
最后完整的代码如下:
#include
using namespace std;
class Rectangle
{
private:
int width, height;
public:
void r2(int w, int h);
int area();
};
void Rectangle::r2(int w, int h)
{
width=w;
height=h;
}
int Rectangle::area()
{
return width * height;
}
int main()
{
Rectangle r1;
r1.r2(3,5) ;
cout