首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

请各位帮小弟我改一改

2012-05-04 
请各位帮我改一改#include stdafx.h#includeiostream#includecmathusing namespace stdclass point

请各位帮我改一改
#include "stdafx.h"

#include<iostream>
#include<cmath>
using namespace std;
class point
{
public:
  point(int xx=0,int yy=0)

x=xx;
y=yy;
}
  point(point &p);
  int getX()
  {
return x;
  }
  int getY()
  {
return y;
  }
private:
int x,y;
};
point::point(point &p)
{
x=p.x;
y=p.y;
cout<<"calling the copy constructor of point"<<endl;
}
class Line
{
public:
Line(point xp1,point xp2);
Line(Line &1);
double getLen()
{
return len;
}
private:
point p1,p2;
double len;
};
Line::Line(point xp1,point xp2):p1(xp1),p2(xp2)
{
cout<<"calling constructor of Line"<<endl;
double x=static_cast<double>(p1.getX()-p2.getX());
double y=static_cast<double>(p1.getY()-p2.getY());
len=sqrt(x*x+y*y);
}
Line::Line(Line &1):p1(1.p1),p2(1.p2)
{
cout<<"calling the copy congtructor of ling"<<endl;
len=1.len;

int main(int argc, char* argv[])
{
point myp1(1,1),myp2(4,5);
Line line(myp1,myp2);
Line line2(line);
cout<<"the length of the line is:";
cout<<line.getLen ()<<endl;
cout<<"the length of the ling2 is:";
cout<<ling2.getLen()<<endl;
return 0;
}


[解决办法]

Line::Line(Line &1):p1(1.p1),p2(1.p2)
{
cout<<"calling the copy congtructor of ling"<<endl;
len=1.len;
}

Line(Line &1);
以上两处代码,形式参数用的是数字。变量不能够直接声明为数字,将这两个地方修改一下就可以了。

热点排行