请各位大神帮忙看一下,下面这段程序哪里出错了??谢谢!
#include<iostream>#include<cmath>#include<cassert>usingnamespacestd;classpoint{public...
#include<iostream>
#include<cmath>
#include<cassert>
using namespace std;
class point
{
public:
point();
point(int xx,int yy);
~point();
point(point& p2);
void move(int x=0,int y=0);
private:
int x,y;
};
point::point(){cout<<"point的默认构造函数"<<endl;}
point::point(int xx,int yy){x=xx;y=yy;cout<<"point的构造函数"<<endl;}
point::~point(){cout<<"point的析构函数"<<endl;}
point::point(point& p2){x=p2.x;y=p2.y;cout<<"复制构造函数"<<endl;}
void point::move(int x,int y){this->x=x;this->y=y;cout<<"x="<<x<<" "<<"y="<<y<<endl;}
class arraypoint
{
public:
arraypoint(int size){points=new point[size];cout<<"arraypoint的构造函数"<<endl;}
~arraypoint(){delete []points;cout<<"arraypoint的析构函数"<<endl;}
point element(int index){assert(index>=0 && index<size);return points[index];}
private:
int size;point* points;
};
int main()
{
int count;
cout<<"please enter the number of count"<<endl;
cin>>count;
arraypoint arraypoint1(count);
arraypoint1.element(0).move(3,4);
arraypoint1.element(1).move(4,5);
return 0;
system("pause");
} 展开
#include<cmath>
#include<cassert>
using namespace std;
class point
{
public:
point();
point(int xx,int yy);
~point();
point(point& p2);
void move(int x=0,int y=0);
private:
int x,y;
};
point::point(){cout<<"point的默认构造函数"<<endl;}
point::point(int xx,int yy){x=xx;y=yy;cout<<"point的构造函数"<<endl;}
point::~point(){cout<<"point的析构函数"<<endl;}
point::point(point& p2){x=p2.x;y=p2.y;cout<<"复制构造函数"<<endl;}
void point::move(int x,int y){this->x=x;this->y=y;cout<<"x="<<x<<" "<<"y="<<y<<endl;}
class arraypoint
{
public:
arraypoint(int size){points=new point[size];cout<<"arraypoint的构造函数"<<endl;}
~arraypoint(){delete []points;cout<<"arraypoint的析构函数"<<endl;}
point element(int index){assert(index>=0 && index<size);return points[index];}
private:
int size;point* points;
};
int main()
{
int count;
cout<<"please enter the number of count"<<endl;
cin>>count;
arraypoint arraypoint1(count);
arraypoint1.element(0).move(3,4);
arraypoint1.element(1).move(4,5);
return 0;
system("pause");
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询