请大家帮我看看,错误有些多,希望大家能帮我改改.谢谢!
#include<iostream>
using namespace std;
class Rectangle{
private:Line line1;
public:
Rectangle(Line a):line1(a){}
int mianji(){int s=line1.length1*line1.length2;
return s;}
};
class Line{
private :Point p1,p2;
int length1;
int length2;
public:Line (Point a,Point b):p1(a),p2(b)
{length1=p1.x-p2.x;
length2=p1.y-p2.y;}
Line (Line &p){length1=p.length1;
length2=p.length2;}
};
class Point {
private:int x;
int y;
public:Point (int a ,int b){x=a;y=b;}
Point (Point &p){x=p.x;y=p.y;}
};
void main(){
Point m1(10,20),m2(5,10);
Line p1(m1,m2);
Rectangle rectangle(p1);
cout<<"面积是:"<<rectangle.mianji()<<endl;
}
错误调试:
--Configuration: 11 - Win32 Debug--------------------
Compiling...
11.cpp
D:\学习文件\CL\4-9\11\11.cpp(5) : error C2146: syntax error : missing ';' before identifier 'line1'
D:\学习文件\CL\4-9\11\11.cpp(5) : error C2501: 'Line' : missing storage-class or type specifiers
D:\学习文件\CL\4-9\11\11.cpp(5) : error C2501: 'line1' : missing storage-class or type specifiers
D:\学习文件\CL\4-9\11\11.cpp(8) : error C2629: unexpected 'class Rectangle ('
D:\学习文件\CL\4-9\11\11.cpp(8) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
D:\学习文件\CL\4-9\11\11.cpp(14) : error C2146: syntax error : missing ';' before identifier 'p1'
D:\学习文件\CL\4-9\11\11.cpp(14) : error C2501: 'Point' : missing storage-class or type specifiers
D:\学习文件\CL\4-9\11\11.cpp(14) : error C2501: 'p1' : missing storage-class or type specifiers
D:\学习文件\CL\4-9\11\11.cpp(14) : error C2501: 'p2' : missing storage-class or type specifiers
D:\学习文件\CL\4-9\11\11.cpp(17) : error C2629: unexpected 'class Line ('
D:\学习文件\CL\4-9\11\11.cpp(17) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
D:\学习文件\CL\4-9\11\11.cpp(32) : error C2660: 'Line::Line' : function does not take 2 parameters
D:\学习文件\CL\4-9\11\11.cpp(33) : error C2440: 'initializing' : cannot convert from 'class Line' to 'class Rectangle'
No constructor could take the source type, or constructor overload resolution was ambiguous
执行 cl.exe 时出错.
11.obj - 1 error(s), 0 warning(s)