#include <iostream.h>
class Point
{
public:
Point(double x,double y);
Point();
Point(Point&A);
~Point();
void Sets(double x,double y);
void Prints();
private:
double X,Y;
};
Point::Point(double x,double y)
{
X=x;Y=y;
}
Point::Point()
{}
Point::Point(Point&A)
{
X=A.X+1;Y=A.Y+1;
cout<<"拷贝函数调用后坐标("<<X<<","<<Y<<")"<<endl;
}
Point::~Point()
{
cout<<"destructor called "<<X<<" "<<Y<<endl;
}
void Point::Sets(double x,double y)
{
X=x;Y=y;
}
void Point::Prints()
{
cout<<"坐标是 ("<<X<<","<<Y<<")"<<endl;
}
class Line:public Point
{
public:
Line(double x,double y,double s);
Line();
Line(Line&P);
~Line();
void Setl(double x,double y,double s);
void Printl();
private:
double S;
};
Line::Line(double x,double y,double s)
{
Point(x,y);
S=s;
}
Line::Line()
{}
Line::Line(Line &P)
{
Point(&P);S=P.S+1;
cout<<"S="<<S<<endl;
}
Line::~Line()
{
cout<<"destructor called ";
Prints();
cout<<"S="<<S<<endl;
}
void Line::Setl(double x,double y,double s)
{
Sets(x,y);
S=s;
}
void Line::Printl()
{
Prints();
cout<<"斜率是 "<<S<<endl;
}
void main()
{
Point P(3.0,4.0);
Point P1(P);
P.Prints();
P.Sets(5.0,6.0);
P.Prints();
Line L(4.0,5.0,1);
Line L1(L);
L.Printl();
L.Prints();
L.Setl(6.0,7.0,1.2);
L.Printl();
L.Prints();
}
这题在编译的时候,继承类Line的拷贝构造函数有问题
[此贴子已经被作者于2006-6-30 18:37:07编辑过]