为了账号安全,请及时绑定邮箱和手机立即绑定

49.obj - 7 error(s), 0 warning(s)?为什么会这样?

49.obj - 7 error(s), 0 warning(s)?为什么会这样?

慕容3067478 2022-05-13 15:11:44
#include <iostream>using namespace std;class Rect;//类:坐标class Position{private:int x,y;public:Position(int xx=0,int yy=0){x=xx;y=yy;}Position(Position &P){x=P.x;y=P.y;}int Getx(){return x;}int Gety(){return y;}}//类:矩形class Rect{private:Postion dl,ur;int area;public:Rect(Position dlp,Position urp):dl(dlp),ur(urp){area=(ur.Getx()-dl.Getx())*(ur.Gety()-dl.Gety());}~Rect(Rect &R):dl(R.dl),ur(R.ur){area=R.area;}int GetArea(){return area;}}//主函数void main(){Position dl1(0,0);Position ur1(4,5);Rect r1(dl1,ur1);cout<<r1.GetArea<<endl;}--------------------Configuration: 49 - Win32 Debug--------------------Compiling...49.cppD:\Program Files\Microsoft Visual Studio\MyProjects\49\49.cpp(33) : error C2236: unexpected 'class' 'Rect'D:\Program Files\Microsoft Visual Studio\MyProjects\49\49.cpp(33) : error C2143: syntax error : missing ';' before '{'D:\Program Files\Microsoft Visual Studio\MyProjects\49\49.cpp(33) : error C2447: missing function header (old-style formal list?)D:\Program Files\Microsoft Visual Studio\MyProjects\49\49.cpp(59) : error C2079: 'r1' uses undefined class 'Rect'D:\Program Files\Microsoft Visual Studio\MyProjects\49\49.cpp(59) : error C2078: too many initializersD:\Program Files\Microsoft Visual Studio\MyProjects\49\49.cpp(59) : error C2440: 'initializing' : cannot convert from 'class Position' to 'int'No user-defined-conversion operator available that can perform this conversion, or the operator cannot be calledD:\Program Files\Microsoft Visual Studio\MyProjects\49\49.cpp(60) : error C2228: left of '.GetArea' must have class/struct/union typeError executing cl.exe.49.obj - 7 error(s), 0 warning(s)
查看完整描述

1 回答

?
月关宝盒

TA贡献1772条经验 获得超5个赞

给,已经都改好了,具体的请看注释:

#include <iostream>
using namespace std;
class Rect;

//类:坐标
class Position
{
private:
int x,y;
public:
Position(int xx=0,int yy=0)
{
x=xx;
y=yy;
}
Position(Position &P)
{
x=P.x;
y=P.y;
}
int Getx()
{
return x;
}
int Gety()
{
return y;
}
};//class定义最后要加分号

//类:矩形
class Rect
{
private:
Position dl,ur; //Postion改为Position
int area;
public:
Rect(Position dlp,Position urp):dl(dlp),ur(urp)
{
area=(ur.Getx()-dl.Getx())*(ur.Gety()-dl.Gety());
}
~Rect(void) //析构函数没有参数
{
//area=R.area; //一般析构函数不进行任何处理
}
int GetArea()
{
return area;
}
};//class定义最后要加分号

//主函数
void main()
{
Position dl1(0,0);
Position ur1(4,5);
Rect r1(dl1,ur1);
cout<<r1.GetArea<<endl;

}


查看完整回答
反对 回复 2022-05-16
  • 1 回答
  • 0 关注
  • 274 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信