![]() |
#2
黄昏乐章2015-07-23 17:15
|

#include<iostream>
#include<cassert>
using namespace std;
class point{
public:
point(int xx = 0, int yy = 0)
{
x = xx;
y = yy;
}
point(point &a);
int getX(){
return x;
}
int getY()
{
return y;
}
void move(int newX, int newY){
x = newX;
y = newY;
cout << getX() << "," << getY() << endl;
}
private:
int x, y;
};
class arrayofpoints{
public:
arrayofpoints(int size) : sizes(size){
points = new point[size];
}
~arrayofpoints(){
cout << "deleteing..." << endl;
delete[] points;
}
point& element(){
return *(points++);//一改这里能运行但是最后说了句debug assertion failed! 我输入了3或者4
}
private:
point *points;
int sizes;
};
int main()
{
int count;
cout << "please enter the count of points: ";
cin >> count;
arrayofpoints Points(count);
Points.element().move(12, 56);
Points.element().move(5, 0);
return 0;
}
#include<cassert>
using namespace std;
class point{
public:
point(int xx = 0, int yy = 0)
{
x = xx;
y = yy;
}
point(point &a);
int getX(){
return x;
}
int getY()
{
return y;
}
void move(int newX, int newY){
x = newX;
y = newY;
cout << getX() << "," << getY() << endl;
}
private:
int x, y;
};
class arrayofpoints{
public:
arrayofpoints(int size) : sizes(size){
points = new point[size];
}
~arrayofpoints(){
cout << "deleteing..." << endl;
delete[] points;
}
point& element(){
return *(points++);//一改这里能运行但是最后说了句debug assertion failed! 我输入了3或者4
}
private:
point *points;
int sizes;
};
int main()
{
int count;
cout << "please enter the count of points: ";
cin >> count;
arrayofpoints Points(count);
Points.element().move(12, 56);
Points.element().move(5, 0);
return 0;
}
在书里扒了了代码自己改改