#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.cpp
D:\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 initializers
D:\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 called
D:\Program Files\Microsoft Visual Studio\MyProjects\49\49.cpp(60) : error C2228: left of '.GetArea' must have class/struct/union type
Error executing cl.exe.
49.obj - 7 error(s), 0 warning(s)
月关宝盒
相关分类