用vc6.0编译的c++,不知道哪里错了

来源:百度知道 编辑:UC知道 时间:2024/09/21 22:14:56
#include<iostream.h>
#include<math.h>
class point
{
public:
point(double xx=0,double yy=0){x=xx;y=yy;}
point(point&p);
double getx(){return x;}
double gety(){return y;}
private:
double x,y;
};
point::point(point&p)
{x=p.x;y=p.y;
cout<<"点类拷贝构造函数被调用"<<endl;
}
class distance
{
public:
distance(point sp1,point sp2);

double getdist(){return dist;}
private:
point p1,p2;
double dist;
};
distance::distance(point sp1,point sp2):p1(sp1),p2(sp2)
{
cout<<"distance构造函数被调用"<<endl;
double a=p1.getx()-p2.getx();
double b=p1.gety()-p2.gety();
dist=sqrt(a*a+b*b);
}
void main()
{
point myp1(1,1),myp2(4,5);
distance mydist(myp1,myp2);
cout<<"两点间的距离是:"<<mydist.getdist()<<endl;
}

我运行过了 没有错误
记过输出是 :
点类拷贝构造函数被调用
点类拷贝构造函数被调用
点类拷贝构造函数被调用
点类拷贝构造函数被调用
distance构造函数被调用
两点间的距离是:5
你的vc编译器可能有问题,我可以保证你程序没问题。

你的distance类重定义了。xutility中也有一个定义:
template<class _InIt> inline
typename iterator_traits<_InIt>::difference_type
distance(_InIt _First, _InIt _Last)
{ // return distance between iterators
typename iterator_traits<_InIt>::difference_type _Off = 0;
_Distance2(_First, _Last, _Off, _Iter_cat(_First));
return (_Off);
}