注册 登录
编程论坛 新人交流区

[求助]编的这个程序哪出了问题

佑礼 发布于 2007-10-28 10:51, 440 次点击

#include<iostream>
#include<cmath>
using namespace std;

class Point
{
public:
Point(double x,double y){X = x;Y = y;}
Point(Point &p);
~Point(){}
double Getx() {return X;}
double Gety() {return Y;}
private:
double X;
double Y;
};

Point::Point(Point &p)
{
X = p.X;
Y = p.Y;
}


class Rectangle
{
public:
Rectangle(Point p1,Point p2);
Rectangle(Rectangle &p);
~Rectangle(){}
double Getarea(){return area;}
private:
Point q1;
Point q2;
double area;
};

Rectangle:: Rectangle (Point p1,Point p2):q1(p1),q2(p2)
{
double a;
a = double((q1.Getx())-(q2.Getx()));
double b ;
b = double((q1.Gety())-(q2.Gety()));
area = sqrt(a*a*b*b);
}

Rectangle::Rectangle(Rectangle &p)
{
area = p.area; //出错error C2512: 'Point' : no appropriate default constructor available
}


void main()
{
Point d1(1,0),d2(2,0);
Rectangle r1(d1,d2);
cout<<r1.Getarea<<endl;

}

[此贴子已经被作者于2007-10-29 17:38:39编辑过]

7 回复
#2
佑礼2007-10-29 17:38
大家不要54好吧。。。
#3
ybw0012007-10-29 19:08

#include<iostream>
#include<cmath>
using namespace std;

class Point
{
public:
Point(double x,double y){X = x;Y = y;}
Point(Point &p);
~Point(){}
double Getx() {return X;}
double Gety() {return Y;}
private:
double X;
double Y;
};

Point::Point(Point &p)
{
X = p.X;
Y = p.Y;
}


class Rectangle
{
public:
Rectangle(Point p1,Point p2);
Rectangle(Rectangle &p);
~Rectangle(){}
double Getarea(){return area;}
private:
Point q1;
Point q2;
double area;
};

Rectangle:: Rectangle (Point p1,Point p2):q1(p1),q2(p2)
{
double a;
a = abs(double((q1.Getx())-(q2.Getx())));
double b ;
b = abs(double((q1.Gety())-(q2.Gety())));
area = sqrt(a*b);
}

Rectangle::Rectangle(Rectangle &p):q1(p.q1 ),q2(p.q2)//改正方法!
{

area = p.area; //出错error C2512: 'Point' : no appropriate default constructor available
}


void main()
{
Point d1(1,2),d2(3,4);
Rectangle r1(d1,d2);
cout<<r1.Getarea()<<endl;

}

这样应该行了,你试试吧!!

[此贴子已经被作者于2007-10-29 19:11:31编辑过]

#4
p03032302007-10-29 19:11
顶楼上
#5
lonely002007-10-29 20:17
顶起
#6
baoguoping2007-10-29 21:08
C语言的.,晕..早忘的差不多了....
#7
佑礼2007-10-29 23:59
还是有错,说‘p' : undeclared identifier
#8
佑礼2007-10-30 00:11
行了,谢谢大家了
1