拷贝构造函数运行不知道为什么出错
刚刚开始学c++,在拷贝函数的时候我在vc++6.0里面运行出错,不知道为什么。错误说cpp(3) : error C2871: 'std' : does not exist or is not a namespace我觉得是#include的问题。看了很多人的拷贝构造函数,头文件都是#include <iostream>,没有.h
如果去掉using namespace std,运行就会说定义的point类失败,确实不知道为什么。。。,请高手帮帮忙解答:)
#include <iostream.h>
#include <math.h>
using namespace std;
class point
{
private:
int X,Y;
public:
point(int xx=0,int yy=0){X=xx;Y=yy;}
point(point &p);
int getx(){return X;}
int gety(){return Y;}
};
point::point(point &p)
{
X=p.X; Y=p.Y;
cout<<"point拷贝构造函数被调用"<<endl;
}
class distance
{
private:
point p1,p2;
double dist;
public:
distance(point xp1,point xp2);
double getdis(){return dist;}
};
distance::distance(point xp1,point xp2):p1(xp1),p2(xp2)
{
cout<<"distance构造函数被调用"<<endl;
double x=double(p1.getx()-p2.getx());
double y=double(p1.gety()-p2.gety());
dist=(x*x+y*y);
}
void main()
{
point myp1(1,2),myp2(4,5);
distance myd(myp1,myp2);
cout<<"the distance is:"<<endl;
cout<<myd.getdis()<<endl;
}